TensorFlow는 Google이 2015년 오픈소스로 공개한 머신러닝·딥러닝 프레임워크다. Keras API로 쉽게 사용 가능하며, 모바일(TF Lite), 웹(TF.js), 클라우드(TF Serving) 등 다양한 배포 환경을 지원한다.
Keras API 사용
python
import tensorflow as tf
from tensorflow import keras
# 순차 모델
model = keras.Sequential([
keras.layers.Dense(256, activation='relu', input_shape=(784,)),
keras.layers.Dropout(0.2),
keras.layers.Dense(128, activation='relu'),
keras.layers.Dense(10, activation='softmax')
])
model.compile(
optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy']
)
model.fit(X_train, y_train, epochs=10, batch_size=32,
validation_split=0.2)
TF Lite (모바일 배포)
python
# 모델 변환
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
# 안드로이드/iOS에서 실행
with open('model.tflite', 'wb') as f:
f.write(tflite_model)
관련 개념
- •PyTorch — TensorFlow의 경쟁 프레임워크
- •딥러닝 — TensorFlow의 주요 활용
- •CUDA — TensorFlow GPU 가속
참고문헌
- •TensorFlow 공식 문서: tensorflow.org