Coolx World - Programming
tensorflow (개발일반)
2021-05-21 15:53 - swindler
아래 코드는 tensowflow 2.x 에서
1.x 예제로 공부하다보니 1.x 버전으로 사용하게끔 하였음

CUDA를 지원하지 않아, 매번 에러메세지가 뜨기 때문에
LOG_LEVEL을 조정했음




import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 로그레벨 조정 2 -> INFO, WARNING 출력 안함

#import tensorflow as tf

# tensorflow 1.x 버전으로 사용
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

X = tf.placeholder(tf.float32, [None, 3])
print(X)

input = [[1,2,3],[4,5,6]]

W = tf.Variable(tf.random_normal([3,2]))

b = tf.Variable(tf.random_normal([2,1]))

hypothesis = tf.matmul(X,W) + b

sess = tf.Session()

sess.run(tf.global_variables_initializer())

print("-------- INPUT --------")
print(input)

print("-------- W --------")
print(sess.run(W))

print("-------- b --------")
print(sess.run(b))

print("-------- hypothesis --------")
print(sess.run(hypothesis, feed_dict={X: input}))
sess.close()

Copyright © 1999-2020, swindler.

  2HLAB   2HLAB_Blog   RedToolBox   Omil   Omil_Blog