텐서플로우 버전은 2.4 버전을 사용했습니다.
예전에 사용한 placeholder, session은 2.0 버전 이후로 사라지고 파이선 자체의 함수를 이용하니 참고해주세요
import tensorflow as tf
import numpy as np
hello = tf.constant("Hello, TensorFlow!")
print(hello)
node1 = tf.constant(3.0,tf.float32)
node2 = tf.constant(4.0,tf.float32)
print("node1:", node1, "node2:", node2)
# session이 사라진 텐서 플로우에서는 그냥 def를 사용할 수 있다.
def forward(a,b):
return a + b
out_a = forward(node1,node2)
print(out_a)
# 더하기 연산을 제공해주기도 한다.
node3 = tf.add(node1,node2)
print(node3)
node4 = tf.constant([2.,3.,4], tf.float32)
node5 = tf.constant([3.,2.,1], tf.float32)
print(node4+node5)
기본적인 더하기 연산과 같은 부분을 실행 할수 있다
3 # a rank 0 tensor; this is a scalar with shape []
[1. ,2., 3.] # a rank 1 tensor; this is a vector with shape [3]
[[1., 2., 3.], [4., 5., 6.]] # a rank 2 tensor; a matrix with shape [2, 3]
[[[1., 2., 3.]], [[7., 8., 9.]]] # a rank 3 tensor with shape [2, 1, 3]
텐서플로우를 이해하기 위해서는 Rank 와 Shape를 잘 이해하면 좋다
Rank 는 차원을 의미하며
Shape는 텐서의 모양을 나타낸다고 생각하면 된다. 가장 안쪽의 요소부터 갯수를 세어주면 된다.
참고 블로그
[TensorFlow 2.0] 사라진 Session 모듈 "쉬운 대체 방법!"
안녕하세요! 비버입니다! :D 저는 요즘 유튜브에서 김성훈 교수님의 '모두를 위한 딥러닝 강좌 시즌1' 를 들으며 텐서플로우를 이용한 딥러닝을 복습해보고 있어요. 그런데 시작부터 부닥치는 문
bbdata.tistory.com
https://eclipse360.tistory.com/40
반응형
'AI > tensorflow' 카테고리의 다른 글
딥러닝 모델 체크 리스트 (0) | 2022.06.07 |
---|---|
[tensorflow] 모델 저장과 복원 - tf.keras.callbacks.ModelCheckpoint (0) | 2022.04.28 |