[ํ์ด์ฌ ๋จธ์ ๋ฌ๋] ํ ์ํ๋ก์ฐ ์ค์น & ํ ์ํ๋ก์ฐ ์ํฌํธํ์ฌ hello world ์ถ๋ ฅํ๊ธฐ
[ํ์ต์๋ฃ] ํ์ด์ฌ ํ ์ํ๋ก์ฐ & ๋จธ์ ๋ฌ๋ ๊ธฐ์ด ๊ฐ์ข
๐ฟ๏ธํ
์ํ๋ก์ฐ ์ค์น๋ฐฉ๋ฒ๐ฟ๏ธ
1. cmd(๋ช ๋ น ํ๋กฌํํธ) ์คํ
2. pip3 install tensorflow ์ ๋ ฅ
์ค์น ํ์ธ ๋ฐฉ๋ฒ: 2๋ฒ์ ๋ช ๋ น์ด๋ฅผ ํ ๋ฒ ๋ ์ ๋ ฅํ๊ณ , Requirement already satisfied๋ผ๋ ๋ฌธ๊ตฌ๊ฐ ๋จ๋์ง ํ์ธํ๋ค. ํด๋น ๋ฌธ๊ตฌ๊ฐ ๋ฌ๋ค๋ฉด ์ค์น๋ฅผ ์๋ฃํ ๊ฒ์ด๋ค.
๐hello world ์ถ๋ ฅ & ์ด์๐
ํด๋น ๊ฐ์๋ 2๋ ์ ๊ฐ์๋ผ tensorflow ๋ฒ์ ์ด 2.0.0 ๋ณด๋ค ๋ฎ๋ค. ๊ทธ๋ ๊ธฐ์ ๊ฐ์์์ ์๋ ค์ฃผ๋๋๋ก "tf.Session()"์ ์ ๋ ฅํ์ฌ hello world๋ฅผ ์ถ๋ ฅํ๊ณ ์ ํ๋ค๋ฉด, ์ค๋ฅ๊ฐ ๋๋ค.
import tensorflow as tf
hello=tf.constant('hello world') #์์์ ์
sess=tf.Session() #์ธ์
์ ๋ฃ๊ธฐ
print(sess.run(hello))
์ค๋ฅ์ ๋ด์ฉ์ ๋ค์๊ณผ ๊ฐ๋ค.
AttributeError: module 'tensorflow' has no attribute 'Session'
๋๋ tensorflow 2.0.0 ์ดํ ๋ฒ์ ๋ถํฐ tf.Session()์ด ์ฌ์ฉ๋์ง ์๋๋ค ์ ๋๋ก ๊ฐ๋ตํ ์ดํดํ๋ค.
ํด๋น ์ค๋ฅ๋ฅผ ํผํ๊ธฐ ์ํด์๋ ์ด์ ๊ฐ์ด ์ฝ๋๋ฅผ ๋ณ๊ฒฝํ๋ฉด ๋๋ค.
import tensorflow as tf
with tf.compat.v1.Session() as sess: #์ฝ๋ ์ถ๊ฐ
hello=tf.constant('hello world') #์์์ ์
#sess=tf.Session() #์ญ์
print(sess.run(hello))

๋ณ๊ฒฝ ํ, ์ด๋ ๊ฒ ์ ์์ ์ผ๋ก ์ถ๋ ฅ๋๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
๐พ๋จธ์ ๋ฌ๋ ๊ธฐ์ด ๊ฐ์ข 1๊ฐ ํ์ต ์๋ฃ๐พ