File size: 1,214 Bytes
12f2295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
import os
import tensorflow as tf
from tensorflow.keras.layers import Input, Flatten, Dense, Subtract
from tensorflow.keras.models import Model
import sys
sys.path.append(os.getcwd())
from config import SIA_MODEL_PATH

def build_dummy_siamese():
    inp_a = Input(shape=(224, 224, 1), name="img_a")
    inp_b = Input(shape=(224, 224, 1), name="img_b")
    encoder_input = Input(shape=(224, 224, 1))
    x = Flatten()(encoder_input)
    x = Dense(16, activation="relu")(x)
    encoder = Model(encoder_input, x)
    encoded_a = encoder(inp_a)
    encoded_b = encoder(inp_b)
    distance = Subtract()([encoded_a, encoded_b])
    model = Model(inputs=[inp_a, inp_b], outputs=distance)
    return model

if __name__ == "__main__":
    print("Building and converting dummy Siamese model...")
    model = build_dummy_siamese()
    converter = tf.lite.TFLiteConverter.from_keras_model(model)
    converter.optimizations = [tf.lite.Optimize.DEFAULT]
    tflite_model = converter.convert()
    os.makedirs(os.path.dirname(SIA_MODEL_PATH), exist_ok=True)
    with open(SIA_MODEL_PATH, "wb") as f:
        f.write(tflite_model)
    print(f"✅ Dummy TFLite signature model saved to '{SIA_MODEL_PATH}'")