์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ™œ์„ฑํ™” ํ•ด์ฃผ์„ธ์š”

Tensorflow

 ·  โ˜• 2 min read  ·  โœ๏ธ brinst · ๐Ÿ‘€... ์กฐํšŒ์ˆ˜

๋ฐฐ์›Œ์•ผ ํ•˜๋Š” ์ด์œ 

contributors๊ฐ€ ์ œ์ผ ๋งŽ๊ณ  ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ๋žŒ๋“ค๋„ ์ œ์ผ ๋งŽ์Œ

Tensorflow๋ž€?

Tesorflow is an open source software library for numerical computation using data flow graphs.

ํ…์„œ๋ธ”๋กœ๋Š” data flow ๊ทธ๋ž˜ํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ˆ˜์น˜์ ์ธ ๊ณ„์‚ฐ์„ ํ•  ์ˆ˜ ์žˆ๋Š” ์˜คํ”ˆ์†Œ์Šค ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.

Data Flow Graph

ํ…์„œ ํ”Œ๋กœ์šฐ๋Š”ย dataflow graphํ˜•์‹์„ ๋”ฐ๋ฅด๋Š”๋ฐ, ์ด๋Š” ๊ธฐ์กด์˜ programming ๋ฐฉ์‹๊ณผ๋Š” ๋‹ค๋ฅด๊ฒŒ computation ์ˆœ์„œ๊ฐ€ ๊ฐ๊ฐ์˜ operation๊ฐ„์˜ ๊ด€๊ณ„์— ๋”ฐ๋ผ ๊ฒฐ์ •๋˜๋Š” ๊ฒƒ์ด๋‹ค. ์ด๋Š”ย Parallel compution์— ์•„์ฃผ ์œ ์šฉํ•œ ๊ฐœ๋…์ธ๋ฐ, ๊ฐ๊ฐ์˜ย node๋Š” ์—ฐ์‚ฐ์˜ ์ตœ์†Œ ๋‹จ์œ„๋ฅผ ๋งํ•˜๋ฉฐย edge๋Š” ์—ฐ์‚ฐ์— ์‚ฌ์šฉ๋˜๋Š” data๋ฅผ ํ‘œํ˜„ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๋‘ ๊ฐœ์˜ matrix๋ฅผ ๊ณฑํ•ด์„œ ํ•˜๋‚˜์˜ matrix ๊ฒฐ๊ณผ๋ฅผ ๋งŒ๋“œ๋Š”ย tf.matmul๋ฅผ ์ƒ๊ฐํ•ด๋ณด์ž. ์ด operation์—๋Š” 2๊ฐœ์˜ matrix input์„ ์˜๋ฏธํ•˜๋Š” 2๊ฐœ์˜ incoming edge, ์—ฐ์‚ฐ์„ ๋‹ด๋‹นํ•˜๋Š” node ๊ทธ๋ฆฌ๊ณ  matrix multiplication์˜ ๊ฒฐ๊ณผ๋ฅผ ์˜๋ฏธํ•˜๋Š” 1๊ฐœ์˜ outgoing edge๊ฐ€ ์กด์žฌํ•œ๋‹ค.

Node โ†’ operation

edge โ†’ data

tensors_flowing.gif

Install tensorflow

ํ˜„์žฌ ๋‚ด ๋งฅ๋ถ์—๋Š” python์ด ์„ค์น˜ ๋˜์–ด์žˆ๋‹ค.

python์„ ์„ค์น˜ํ•˜๋ฉด pip๋„ ์„ค์น˜๋˜๋Š” ์ค„ ์•Œ๊ณ  ์žˆ์—ˆ๋Š”๋ฐ, ๋งฅ์—์„œ๋Š” ์•„๋‹Œ ๊ฐ€๋ณด๋‹ค.

์œ„ ๊ฒฝ์šฐ๋Š” ํŒŒ์ด์ฌ ํ™ˆํŽ˜์ด์ง€์—์„œ pkg๋ฅผ ์ง์ ‘ ๋‹ค์šด๋ฐ›์•„ ์„ค์น˜ํ•œ ๊ฒฝ์šฐ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ๋ผ๊ณ  ํ•œ๋‹ค.

๋”ฐ๋ผ์„œ ๋”ฐ๋กœ pip๋ฅผ ์„ค์น˜ํ•ด์ฃผ์ž.

ahndoori

์œ„ ๋ฐฉ๋ฒ•๋„ ์กด์žฌํ•˜๊ณ  ์•„๋ž˜์˜ ๋ฐฉ๋ฒ• ์ฒ˜๋Ÿผ brew ๋กœ ์žฌ์„ค์น˜ ํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์กด์žฌํ•œ๋‹ค.

1
2
brew uninstall python3
brew install python3

pip ์„ค์ •์ด ์™„๋ฃŒ ๋˜์—ˆ์œผ๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ tensorflow๋ฅผ ์„ค์น˜ํ•œ๋‹ค.

1
2
pip install --upgrade tensorflow
pip install --upgrade tensorflow-gpu
  • ๋„์ปค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์กด์žฌํ•œ๋‹ค. (docker ๋งŒ์„ธ!)

    1
    2
    
    docker pull tensorflow/tensorflow:latest  # Download latest stable image
    docker run -it -p 8888:8888 tensorflow/tensorflow:latest-jupyter  # Start Jupyter server
    

ํ…์„œํ”Œ๋กœ ๋ฒ„์ „ ํ™•์ธ

1
2
import tensorflow as tf
tf.__version__

[ํŒŒ์ด์ฌ] Tensorflow 2.0 session / placeholder ์˜ค๋ฅ˜ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

Install Tensorflow-GPU

๊ธฐ์กด ๋งฅ๋ถ ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” tensorflow-gpu๋ฅผ ํ™œ์„ฑํ•ด์ฃผ์ง€ ์•Š์•˜๋‹ค.(gpu๊ฐ€ amd๊ธฐ ๋•Œ๋ฌธ์—…)
ํ•˜์ง€๋งŒ ์• ํ”Œ์ด M1๋ฅผ ์ง์ ‘ ์ œ์ž‘ํ•˜๊ฒŒ ๋˜๋ฉด์„œ, gpu๋ฅผ ์ง€์›ํ•ด์ฃผ๋ ค๋Š” ๋…ธ๋ ฅ์„ ํ•˜๊ณ ์žˆ๋‹ค….
๋‹ค์Œ ๊ณผ์ •์„ ๋”ฐ๋ผํ•˜๋ฉด m1์—์„œ๋„ gpu๋ฅผ ํ™œ์„ฑํ™”ํ•˜์—ฌ tensorflow๋ฅผ ๋Œ๋ฆด์ˆ˜ ์žˆ๋‹ค.

conda install

https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
์œ„์˜ ๋งํฌ์—์„œ ํŒŒ์ผ์„ ๋ฐ›๊ณ  ๋‹ค์Œ๊ณผ์ •์œผ๋กœ ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ•œ๋‹ค.

1
2
3
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate

์ด ํ›„ ์›ํ•˜๋Š” ํ™˜๊ฒฝ์„ ๋งŒ๋“ค์–ด activation ํ•ด์ค€ํ›„ ๋‹ค์Œ๊ณผ์ •์„ ์ง„ํ–‰ํ•œ๋‹ค.

install the tensorflow dependencies

1
conda install -c apple tensorflow-deps

tensorflow version upgrade

1
2
3
4
5
6
7
# uninstall existing tensorflow-macos and tensorflow-metal
python -m pip uninstall tensorflow-macos
python -m pip uninstall tensorflow-metal
# Upgrade tensorflow-deps
conda install -c apple tensorflow-deps --force-reinstall
# or point to specific conda environment
conda install -c apple tensorflow-deps --force-reinstall -n my_env

install base Tensorflow

1
python -m pip install tensorflow-macos

install tensorflow-metal plugin

1
python -m pip install tensorflow-metal
๊ณต์œ ํ•˜๊ธฐ

brinst
๊ธ€์“ด์ด
brinst
Backend Developer

๋ชฉ์ฐจ