Files
2nd/10_Wiki/Topics/AI_and_ML/TensorFlow-Foundations.md
T
koriweb d8a80f6272 chore(wiki): dangling 링크 canonical 정규화 (768파일/1200건)
이름만 다른(표기 변형) [[위키링크]]를 대상 문서의 canonical 제목으로 치환해
끊겼던 1,200개 링크를 연결. 제목/파일명 정규화 일치만 적용하고 별칭 매칭은
과병합 위험으로 제외(애매성 가드). 원본은 _link_reconcile_backup/ 에 백업.
도구: Datacollect/scripts/link_reconcile_apply.mjs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 12:24:15 +09:00

5.1 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-tensorflow-foundations TensorFlow Foundations 10_Wiki/Topics verified self
TensorFlow
TF2
Keras
none A 0.9 applied
tensorflow
deep-learning
keras
2026-05-10 pending
language framework
Python TensorFlow 2.x / Keras 3

TensorFlow Foundations

매 한 줄

"매 production-first ML framework". Google이 2015년에 release한 graph-based deep learning framework. TF 2.x는 eager-by-default + Keras integration으로 PyTorch-like UX를 제공하지만, 매 핵심 강점은 mobile (TFLite) / web (TF.js) / production serving (TF Serving) 의 cross-platform deployment.

매 핵심

매 TF 2.x 의 essence

  • Eager execution default — 매 tf.function 으로 graph compile (XLA / autograph).
  • Keras 가 high-level API — 매 tf.keras.Model / Sequential / Functional API.
  • tf.data — 매 efficient input pipeline (prefetch, parallel map, sharding).
  • tf.distribute — 매 multi-GPU / TPU strategy (MirroredStrategy, TPUStrategy).

매 PyTorch 와 의 비교 (2026)

  • 연구 share: PyTorch ~85%, TF ~10%. JAX growing.
  • Production share: TF still dominant (TFLite mobile, TF.js web, TF Serving) thanks to mature deployment.
  • Keras 3 (2024+): 매 backend-agnostic — TF / JAX / PyTorch 모두 backend로 사용 가능.

매 응용

  1. Mobile inference (Android / iOS via TFLite).
  2. Browser ML (TF.js — pose detection, on-device LLM).
  3. Recommender systems (TFRS, large embedding tables).

💻 패턴

Sequential model

import tensorflow as tf

model = tf.keras.Sequential([
    tf.keras.layers.Dense(128, activation="relu"),
    tf.keras.layers.Dropout(0.2),
    tf.keras.layers.Dense(10),
])
model.compile(optimizer="adam",
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
              metrics=["accuracy"])
model.fit(x_train, y_train, epochs=5, validation_split=0.1)

Functional API (multi-input)

img_in = tf.keras.Input(shape=(224, 224, 3))
txt_in = tf.keras.Input(shape=(128,), dtype="int32")

img_feat = tf.keras.applications.EfficientNetV2B0(include_top=False, pooling="avg")(img_in)
txt_feat = tf.keras.layers.Embedding(10000, 64)(txt_in)
txt_feat = tf.keras.layers.GlobalAveragePooling1D()(txt_feat)

x = tf.keras.layers.Concatenate()([img_feat, txt_feat])
out = tf.keras.layers.Dense(1, activation="sigmoid")(x)

model = tf.keras.Model([img_in, txt_in], out)

tf.function (graph compile)

@tf.function(jit_compile=True)  # XLA
def train_step(x, y):
    with tf.GradientTape() as tape:
        logits = model(x, training=True)
        loss = loss_fn(y, logits)
    grads = tape.gradient(loss, model.trainable_variables)
    optimizer.apply_gradients(zip(grads, model.trainable_variables))
    return loss

tf.data input pipeline

ds = (tf.data.Dataset.from_tensor_slices((x, y))
      .shuffle(10000)
      .map(preprocess, num_parallel_calls=tf.data.AUTOTUNE)
      .batch(64)
      .prefetch(tf.data.AUTOTUNE))

Multi-GPU

strategy = tf.distribute.MirroredStrategy()
with strategy.scope():
    model = build_model()
    model.compile(...)
model.fit(ds, epochs=10)

TFLite export

converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]  # int8 quantization
tflite_model = converter.convert()
open("model.tflite", "wb").write(tflite_model)

Keras 3 backend swap

import os
os.environ["KERAS_BACKEND"] = "jax"  # or "torch", "tensorflow"
import keras
model = keras.Sequential([keras.layers.Dense(10)])

매 결정 기준

상황 Approach
Mobile/edge deployment TF + TFLite (mature)
Browser inference TF.js
Production serving at scale TF Serving / TFX
Research / new architectures PyTorch (ecosystem)
Backend-agnostic code Keras 3
TPU training TF or JAX

기본값: 매 research 는 PyTorch, deployment 는 TF or ONNX export.

🔗 Graph

🤖 LLM 활용

언제: mobile/web deployment target, TPU access, legacy TF1 codebase migration, TFX pipeline. 언제 X: 매 cutting-edge research model 의 reproduce — 매 PyTorch reference impl 의 dominant.

안티패턴

  • TF1 graph mode 의 cling: 매 tf.compat.v1.Session 의 use 를 새 code 에서 X — 매 TF2 eager + tf.function.
  • Custom training loop 의 unnecessary use: 매 model.fit 으로 충분한 case 에 manual loop 작성.
  • tf.py_function overuse: 매 graph 밖 fallback — 매 performance kill.
  • No prefetch: 매 input pipeline 이 GPU 의 starve.

🧪 검증 / 중복

  • Verified (TensorFlow official docs, Keras 3 release notes, 2024-2026 tracking).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — TF2/Keras3 modern usage + deployment focus