Commit 20ce9c70 authored by Oleh Astappiev's avatar Oleh Astappiev
Browse files

fix: efficientnet and vit working now

parent 1fc2750c
...@@ -5,4 +5,5 @@ matplotlib~=3.5.2 ...@@ -5,4 +5,5 @@ matplotlib~=3.5.2
opencv-python~=4.5.5.64 opencv-python~=4.5.5.64
tqdm~=4.64.0 tqdm~=4.64.0
tensorflow-addons~=0.17.0 tensorflow-addons~=0.17.0
tensorflow_hub~=0.12.0
scipy~=1.8.1 scipy~=1.8.1
...@@ -49,11 +49,11 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1) ...@@ -49,11 +49,11 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1)
# Build full inference model (from image to image vector): # Build full inference model (from image to image vector):
inference_model = siamese.get_inference_model(embedding_model) inference_model = siamese.get_inference_model(embedding_model)
inference_model.save(get_modeldir(model_name + '_inference.tf'), save_format='tf', include_optimizer=False) inference_model.save(get_modeldir(model_name + '_inference.tf'))
# inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False) # inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False)
print('visualization') print('visualization')
# compute vectors of the images and their labels, store them in a tsv file for visualization # compute vectors of the images and their labels, store them in a tsv file for visualization
projection_vectors = siamese.get_projection_model().predict(emb_vectors) projection_vectors = siamese.get_projection_model().predict(emb_vectors)
project_embeddings(projection_vectors, emb_labels, model_name + '_siamese2') project_embeddings(projection_vectors, emb_labels, model_name + '_siamese')
...@@ -49,7 +49,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1) ...@@ -49,7 +49,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1)
# Build full inference model (from image to image vector): # Build full inference model (from image to image vector):
inference_model = siamese.get_inference_model(embedding_model) inference_model = siamese.get_inference_model(embedding_model)
inference_model.save(get_modeldir(model_name + '_inference.tf'), save_format='tf', include_optimizer=False)\ inference_model.save(get_modeldir(model_name + '_inference.tf'))
# inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False) # inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False)
......
...@@ -32,7 +32,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1) ...@@ -32,7 +32,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1)
# Build full inference model (from image to image vector): # Build full inference model (from image to image vector):
inference_model = siamese.get_inference_model(model) inference_model = siamese.get_inference_model(model)
inference_model.save(get_modeldir(model_name + '_inference.tf'), save_format='tf', include_optimizer=False) inference_model.save(get_modeldir(model_name + '_inference.tf'))
# inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False) # inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False)
......
...@@ -50,7 +50,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1) ...@@ -50,7 +50,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1)
# Build full inference model (from image to image vector): # Build full inference model (from image to image vector):
inference_model = siamese.get_inference_model(embedding_model) inference_model = siamese.get_inference_model(embedding_model)
inference_model.save(get_modeldir(model_name + '_inference.tf'), save_format='tf', include_optimizer=False) inference_model.save(get_modeldir(model_name + '_inference.tf'))
# inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False) # inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False)
......
...@@ -49,7 +49,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1) ...@@ -49,7 +49,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1)
# Build full inference model (from image to image vector): # Build full inference model (from image to image vector):
inference_model = siamese.get_inference_model(embedding_model) inference_model = siamese.get_inference_model(embedding_model)
inference_model.save(get_modeldir(model_name + '_inference.tf'), save_format='tf', include_optimizer=False) inference_model.save(get_modeldir(model_name + '_inference.tf'))
# inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False) # inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False)
......
...@@ -14,7 +14,7 @@ class EfficientNetModel(Sequential): ...@@ -14,7 +14,7 @@ class EfficientNetModel(Sequential):
super(EfficientNetModel, self).__init__([ super(EfficientNetModel, self).__init__([
hub.KerasLayer(MODEL_URL, trainable=False) # EfficientNet V2 S backbone, frozen weights hub.KerasLayer(MODEL_URL, trainable=False) # EfficientNet V2 S backbone, frozen weights
]) ])
self.build(TARGET_SHAPE + (3,)) self.build((None,) + TARGET_SHAPE + (3,))
def compile(self, metrics=['accuracy'], **kwargs): def compile(self, metrics=['accuracy'], **kwargs):
super().compile(metrics=metrics, **kwargs) super().compile(metrics=metrics, **kwargs)
......
...@@ -14,7 +14,7 @@ class VitModel(Sequential): ...@@ -14,7 +14,7 @@ class VitModel(Sequential):
super(VitModel, self).__init__([ super(VitModel, self).__init__([
hub.KerasLayer(MODEL_URL, trainable=False) # EfficientNet V2 S backbone, frozen weights hub.KerasLayer(MODEL_URL, trainable=False) # EfficientNet V2 S backbone, frozen weights
]) ])
self.build(TARGET_SHAPE + (3,)) self.build((None,) + TARGET_SHAPE + (3,))
def compile(self, metrics=['accuracy'], **kwargs): def compile(self, metrics=['accuracy'], **kwargs):
super().compile(metrics=metrics, **kwargs) super().compile(metrics=metrics, **kwargs)
......
...@@ -54,7 +54,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1) ...@@ -54,7 +54,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1)
# Build full inference model (from image to image vector): # Build full inference model (from image to image vector):
inference_model = siamese.get_inference_model(embedding_model) inference_model = siamese.get_inference_model(embedding_model)
inference_model.save(get_modeldir(model_name + '_inference.tf'), save_format='tf', include_optimizer=False) inference_model.save(get_modeldir(model_name + '_inference.tf'))
# inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False) # inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False)
......
...@@ -50,7 +50,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1) ...@@ -50,7 +50,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1)
# Build full inference model (from image to image vector): # Build full inference model (from image to image vector):
inference_model = siamese.get_inference_model(embedding_model) inference_model = siamese.get_inference_model(embedding_model)
inference_model.save(get_modeldir(model_name + '_inference.tf'), save_format='tf', include_optimizer=False) inference_model.save(get_modeldir(model_name + '_inference.tf'))
# inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False) # inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False)
......
...@@ -52,7 +52,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1) ...@@ -52,7 +52,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1)
# Build full inference model (from image to image vector): # Build full inference model (from image to image vector):
inference_model = siamese.get_inference_model(embedding_model) inference_model = siamese.get_inference_model(embedding_model)
inference_model.save(get_modeldir(model_name + '_inference.tf'), save_format='tf', include_optimizer=False) inference_model.save(get_modeldir(model_name + '_inference.tf'))
# inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False) # inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False)
......
...@@ -52,7 +52,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1) ...@@ -52,7 +52,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1)
# Build full inference model (from image to image vector): # Build full inference model (from image to image vector):
inference_model = siamese.get_inference_model(embedding_model) inference_model = siamese.get_inference_model(embedding_model)
inference_model.save(get_modeldir(model_name + '_inference.tf'), save_format='tf', include_optimizer=False) inference_model.save(get_modeldir(model_name + '_inference.tf'))
# inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False) # inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False)
......
...@@ -33,7 +33,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1) ...@@ -33,7 +33,7 @@ history = siamese.fit(ds, class_weight={0: 1 / NUM_CLASSES, 1: (NUM_CLASSES - 1)
# Build full inference model (from image to image vector): # Build full inference model (from image to image vector):
inference_model = siamese.get_inference_model(model) inference_model = siamese.get_inference_model(model)
inference_model.save(get_modeldir(model_name + '_inference.tf'), save_format='tf', include_optimizer=False) inference_model.save(get_modeldir(model_name + '_inference.tf'))
# inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False) # inference_model = tf.keras.models.load_model(get_modeldir(model_name + '_inference.tf'), compile=False)
......
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