โ ํ๋ก์ ํธ ๊ฐ์
๋ชฉํ:
ํ๊ธ ํด๋๋ช
์ผ๋ก ์ ๋ฆฌ๋ ๋ค์ค ์์ ์ด๋ฏธ์ง ๋ฐ์ดํฐ์
์ ํ์ฉํด, TensorFlow ๊ธฐ๋ฐ ์ด๋ฏธ์ง ๋ถ๋ฅ ๋ชจ๋ธ์ ํ์ตํ๊ณ , ์ด๋ฅผ Android์์ ์คํ ๊ฐ๋ฅํ .tflite
๋ชจ๋ธ๋ก ๋ณํ.
ํ๊ฒฝ:
- GPU: NVIDIA H100 (80GB)
- Python 3.12 (venv)
- TensorFlow 2.x (GPU ๋ฒ์ ์ค์น)
- ์ด ์ด๋ฏธ์ง ์: ์ฝ 145,000์ฅ
- ํด๋์ค ์: 38๊ฐ (์: ์ด๋ฌต๊ตญ, ์ํ์๋ฌ๋ ๋ฑ)
๐ ๋ฐ์ดํฐ ๊ตฌ์กฐ ๋ฐ ์ ์ฒ๋ฆฌ
- ๋ฐ์ดํฐ ํด๋ ๊ตฌ์กฐ๋ ๋ค์๊ณผ ๊ฐ์:
bashCopyEdit/everything/
โโโ ์ด๋ฌต๊ตญ/
โ โโโ img1.jpg
โ โโโ img2.jpg
โโโ ์๋ฐฐ์ถ/
โ โโโ ...
- TensorFlow์
image_dataset_from_directory()
ํจ์๋ฅผ ํตํด ์๋์ผ๋ก class ์ด๋ฆ์ ํด๋๋ช ๊ธฐ์ค์ผ๋ก ์ธ์.
pythonCopyEdittrain_ds = tf.keras.preprocessing.image_dataset_from_directory(
directory=dataset_path,
image_size=(300, 300),
batch_size=32,
validation_split=0.2,
subset="training",
seed=123
)
๐ง ๋ชจ๋ธ ์ํคํ ์ฒ ๋ฐ ํ์ต
- EfficientNetB3 + GlobalAveragePooling + Dense ๊ตฌ์กฐ
- Data Augmentation ํฌํจ
- ์ด Epoch: 50 / Batch Size: 32
- GPU ๋ฉ๋ชจ๋ฆฌ ์ต์ ํ ๋ฐ ๊ณผ์ ํฉ ๋ฐฉ์ง๋ฅผ ์ํด EarlyStopping ์ฌ์ฉ ๊ณ ๋ ค ๊ฐ๋ฅ
pythonCopyEditbase_model = EfficientNetB3(include_top=False, input_shape=(300, 300, 3), weights='imagenet')
base_model.trainable = False
...
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
- ํ์ต ๊ฒฐ๊ณผ:
train_accuracy โ 91.2%
val_accuracy โ 93.1%
๐ ๋ชจ๋ธ ์ ์ฅ ๋ฐ ๋ณํ
.keras
ํ์์ผ๋ก ์ ์ฅ ํ.tflite
๋ณํtf.lite.TFLiteConverter.from_keras_model()
์ฌ์ฉ
pythonCopyEditmodel.save("my_food_classifier.keras")
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
with open("my_food_classifier.tflite", "wb") as f:
f.write(tflite_model)
๐ฑ ํฅํ Android ์ฐ๋ ์ ํด์ผ ํ ์ผ
- TFLite ๋ชจ๋ธ์ Android Studio ํ๋ก์ ํธ์ ์ถ๊ฐ
labels.txt
ํ์ผ ์์ฑ (class ์ด๋ฆ ์์๋๋ก)TensorImage
,Interpreter
,TensorBuffer
๋ฅผ ํ์ฉํ Inference ์ฝ๋ ์์ฑ- ์
๋ ฅ ํฌ๊ธฐ
(300, 300, 3)
๊ณ ์ ํ์ธ - ๊ฒฐ๊ณผ๊ฐ์
softmax
๊ธฐ๋ฐ ํ๋ฅ ๋ฒกํฐ๋ก ์ถ๋ ฅ๋จ
๐ ํฅํ ๋ณต์ต/์ฌํ ํ์ตํ ์ฃผ์
์ฃผ์ | ์ค๋ช |
---|---|
TFLite ๋ชจ๋ธ ์ต์ ํ | Quantization (int8, float16) ์ฌ์ฉํด ๋ชจ๋ธ ์ฉ๋ ๋ฐ ์ถ๋ก ์๋ ํฅ์ |
์ ํ๋ ๊ฐ์ ์ ๋ต | Fine-tuning, Mixup, Label Smoothing, SAM Optimizer |
๋ค๊ตญ์ด ํด๋์ค ๋์ | ํด๋์ค ์ด๋ฆ์ด ํ๊ธ์ด๋ฏ๋ก Android ๋ด ๋ค๊ตญ์ด ์ง์ ์ฒ๋ฆฌ ํ์ |
YOLO โ TFLite ์ ํ | Object Detection ๋ชจ๋ธ(YOLOv8) โ TFLite ๋ณํ ๊ฒฝ๋ก๋ ๋ณํ ๊ณ ๋ ค |
Custom Android UI | ์ฌ์ฉ์์๊ฒ top-3 class ์์ธก๊ฒฐ๊ณผ๋ฅผ ๋ณด๊ธฐ ์ข๊ฒ ์๊ฐํํ๋ UI ๊ตฌ์ฑ |
โ ๋ง๋ฌด๋ฆฌ
์ด๋ฒ ์์
์ ๊ณ ์ฑ๋ฅ H100 ํ๊ฒฝ์์ ๋๋ ํ๊ธ ๋ฐ์ดํฐ์
์ ํ์ตํ๊ณ , Android ์ฑ์์ ์ฌ์ฉํ ์ ์๋ ์ค์ฉ์ ์ธ .tflite
๋ชจ๋ธ๊น์ง ์์ฑํ ๋งค์ฐ ์ค์ํ ๊ธฐ๋ก์
๋๋ค. ๋ค์ ๋จ๊ณ๋ก๋ ์ค์ Android ๊ธฐ๊ธฐ ํ
์คํธ ๋ฐ ์ค์ฌ์ฉ ์๋๋ฆฌ์ค ๋ฐ์์ด ์ด์ด์ง ์์ ์
๋๋ค.
๋ต๊ธ ๋จ๊ธฐ๊ธฐ