Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Oleh Astappiev
Near-Similar Image Recognition
Commits
6f761cb4
Commit
6f761cb4
authored
May 24, 2022
by
Oleh Astappiev
Browse files
chore: add model names
parent
20ce9c70
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
10 additions
and
10 deletions
+10
-10
src/model/alexnet.py
src/model/alexnet.py
+2
-2
src/model/efficientnet.py
src/model/efficientnet.py
+1
-1
src/model/mobilenet.py
src/model/mobilenet.py
+2
-2
src/model/siamese.py
src/model/siamese.py
+1
-1
src/model/vgg16.py
src/model/vgg16.py
+2
-2
src/model/vit.py
src/model/vit.py
+2
-2
No files found.
src/model/alexnet.py
View file @
6f761cb4
...
...
@@ -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
...
...
src/model/efficientnet.py
View file @
6f761cb4
...
...
@@ -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
):
...
...
src/model/mobilenet.py
View file @
6f761cb4
...
...
@@ -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
...
...
src/model/siamese.py
View file @
6f761cb4
...
...
@@ -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 """
...
...
src/model/vgg16.py
View file @
6f761cb4
...
...
@@ -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
...
...
src/model/vit.py
View file @
6f761cb4
...
...
@@ -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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment