Commit 6f761cb4 authored by Oleh Astappiev's avatar Oleh Astappiev
Browse files

chore: add model names

parent 20ce9c70
......@@ -41,7 +41,7 @@ class AlexNetModel(Sequential):
layers.Dropout(rate=0.5),
layers.Dense(name='unfreeze', units=classes, activation='softmax')
])
], name='alexnet')
def compile(self,
optimizer=tf.optimizers.SGD(learning_rate=0.001),
......@@ -54,7 +54,7 @@ class AlexNetModel(Sequential):
return super().fit(x=x, y=y, batch_size=batch_size, epochs=epochs, callbacks=callbacks, **kwargs)
def get_embedding_model(self):
core = Model(inputs=self.input, outputs=self.layers[-2].output)
core = Model(inputs=self.input, outputs=self.layers[-2].output, name='emb_' + self.name)
for layer in core.layers: layer.trainable = False
return core
......
......@@ -13,7 +13,7 @@ class EfficientNetModel(Sequential):
def __init__(self):
super(EfficientNetModel, self).__init__([
hub.KerasLayer(MODEL_URL, trainable=False) # EfficientNet V2 S backbone, frozen weights
])
], name='efficientnet')
self.build((None,) + TARGET_SHAPE + (3,))
def compile(self, metrics=['accuracy'], **kwargs):
......
......@@ -24,7 +24,7 @@ class MobileNetModel(Model):
x = layers.Activation(activation='softmax', name='predictions')(x)
x = tf.keras.applications.mobilenet.preprocess_input(x)
super(MobileNetModel, self).__init__(inputs=core.input, outputs=x)
super(MobileNetModel, self).__init__(inputs=core.input, outputs=x, name='mobilenet')
def compile(self,
optimizer=tf.keras.optimizers.RMSprop(),
......@@ -38,7 +38,7 @@ class MobileNetModel(Model):
def get_embedding_model(self):
core = Model(inputs=self.input, outputs=self.layers[-7].output)
core = Sequential([core, layers.Flatten()])
core = Sequential([core, layers.Flatten()], name='emb_' + self.name)
for layer in core.layers: layer.trainable = False
return core
......
......@@ -55,7 +55,7 @@ class SiameseModel(Model):
computed_distance = layers.Lambda(cosine_distance)([v1, v2])
# computed_distance = layers.Lambda(euclidean_distance)([v1, v2])
super(SiameseModel, self).__init__(inputs=[emb_input_1, emb_input_2], outputs=computed_distance)
super(SiameseModel, self).__init__(inputs=[emb_input_1, emb_input_2], outputs=computed_distance, name='siamese')
def get_projection_model(self):
""" Projection model is a model from embeddings to image vector """
......
......@@ -38,7 +38,7 @@ class VGG16Model(Model):
**kwargs
)
super(VGG16Model, self).__init__(inputs=model.input, outputs=model.output)
super(VGG16Model, self).__init__(inputs=model.input, outputs=model.output, name='vgg16')
def compile(self,
optimizer=tf.keras.optimizers.RMSprop(),
......@@ -51,7 +51,7 @@ class VGG16Model(Model):
return super().fit(x=x, y=y, batch_size=batch_size, epochs=epochs, callbacks=callbacks, **kwargs)
def get_embedding_model(self):
core = Model(inputs=self.input, outputs=self.layers[-2].output)
core = Model(inputs=self.input, outputs=self.layers[-2].output, name='emb_' + self.name)
for layer in core.layers: layer.trainable = False
return core
......
......@@ -12,8 +12,8 @@ MODEL_URL = "https://tfhub.dev/sayakpaul/vit_s16_fe/1"
class VitModel(Sequential):
def __init__(self):
super(VitModel, self).__init__([
hub.KerasLayer(MODEL_URL, trainable=False) # EfficientNet V2 S backbone, frozen weights
])
hub.KerasLayer(MODEL_URL, trainable=False)
], name='vit')
self.build((None,) + TARGET_SHAPE + (3,))
def compile(self, metrics=['accuracy'], **kwargs):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment