TensorFlow 1.x > 2.x 바뀐 메소드명

Henry Choi·2022년 6월 25일
0

coding

목록 보기
1/2
post-thumbnail

모두를 위한 딥러닝: TensorFlow을 보고 공부하고 있다.

Docker 이미지를 제공하여 그대로 이용할 수 있다는 점은
사전 설치과정에서 꼬일 수 있는 여러가지 문제를 해결해 준다는 장점을 가지지만
최신 버전과 메소드명이 다를 경우 혼란스럽더라.

지금까지 연습해보면서 Docker 이미지 vs. 최신 버전 사이, 보다 정확히는 TensorFlow 1.x vs. TensorFlow 2.x에서 바뀐 메소드를 정리해야겠다 싶었다.

참고할 수 있는 공식문서

직접 검색하면서 정리한 흔적들 (수시 업데이트ing)

Eager_Execution

  • 1.12.0: tf.enable_eager_execution()
  • 2.8.2: 기본 적용, 추가 선언 불필요

tf.compat.v1

  • 2.8.2: compat.v1 메소드들이 eager execution과 호환이 되지 않을 경우,
  • tf.compat.v1.disable_eager_execution() 별도 실행

Random_Set_Seed

  • 1.12.0: tf.set_random_seed()
  • 2.8.2: tf.random.set_seed()

Divide

  • 1.12.0: tf.div()
  • 2.8.2: tf.divide()

Log

  • 1.12.0: tf.log()
  • 2.8.2: tf.math.log()

Train_GradientDescentOptimizer

  • 1.12.0: tf.train.GradientDescentOptimizer()
  • 2.8.2: tf.compat.v1.train.GradientDescentOptimizer()

nn.softmax_cross_entropy_with_logits

  • 1.12.0: tf.nn.softmax_cross_entropy_with_logits_v2()
  • 2.8.2: tf.nn.softmax_cross_entropy_with_logits()

random.normal

  • 1.12.0: tf.random_normal()
  • 2.8.2: tf.random.normal()

tf.compat.v1.Session()

  • 1.12.0: tf.Session()
  • 2.8.2: tf.compat.v1.Session()

tf.compat.v1.global_variables_initializer()

  • 1.12.0: tf.global_variables_initializer()
  • 2.8.2: tf.compat.v1.global_variables_initializer()

Multi Classification(Regression) labeling 할 때

  • SoftMax와 같은 multi-classification 모델 학습시 y 자료형이 integer가 아니면 loss함수 및 gradient_descent함수 계산시 오류가 발생하므로 y 형변환

    # dataset
    xy = np.loadtxt('blahblah.csv', delimiter=',', dtype=np.float32)
    # data x & y via slicing
    x_data = xy[:, 0:-1]
    y_data = xy[:, [-1]]
    # data cast of y_data
    y_data = tf.dtypes.cast(y_data, tf.int32)

profile
an amatuer amuser

0개의 댓글