Tensorflow 01 _ 입문.

1 분 소요


0. 머신러닝 기본 개념

Supervised learning

  • Label이 달려있는 경우 표본(Traning data set)을 주고 학습을 진행함.
  • 일반적인 모델임
  • regression : 범위가 넓은 경우 예측 (ex.학습시간 대비 시험성적 예상 0~100)
  • binary classification (pass/non-pass)
  • multi-label classfication (a,b,c,d,e,f)

UnSupervised learning

  • labeled를 주기 어려운 경우 데이터를 보고 스스로 학습 > 그룹핑 함.

Tensorflow

  • Tensor(데이터 그룹 구조) flow(흐름)
  • 머신러닝 기본 Python 라이브러리


1. Tensorflow 학습

맥OS 환경에서 진행 중.

1) 가상환경 설치

python3 -m venv --system-site-packages virtureInst
# virtureInst는 가상환경 폴더 

2) 가상환경 실행

source virtureInst/bin/activate 
# sh, bash, or zsh

3) 가상환경 종료

deactivate

4) pip로 tensorflow 설치

# 가상환경 실행 상황에서 설치 진행.
# 1.설치
pip install --upgrade
# 2.버전체크
import tensorflow as tf
tf.__version__

5) tensorflow _ print hello

# Tensorflow 버전이 2.0이상 버전인 경우
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
# 이 과정을 진행하면 Session에 에러가 뜨지 않음.

import tnesorflow as tf
hello = tf.constant("hello")
sess = tf.Session()
print(sess.run(hello))

# 출력 : b'hello' / 여기서 b는 byte String이라는 뜻임.

응용

node1 = tf.constant(3.0, tf.float32)
node2 = tf.constant(4.0)
node3 = tf.add(node1, node2)
print(sess.run(node3))
# 7.0 

placeholder

a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
adder_node = a+b
print(sess.run(adder_node, feed_dict = {a:3, b:4.5}))
# 7.5
print(sess.run(adder_node, feed_dict = {a:[1,3], b:[2,4]}))
# [3. 7.]

결론

Tensorflow는 node 그래프를 미리그리고, sess.run()을 통해 출력한다.


* 참고 *

댓글남기기