Skip to content

Commit

Permalink
rename models
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiCorbilla committed Nov 24, 2019
1 parent 8946a30 commit 53fbda0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
16 changes: 8 additions & 8 deletions odir_model_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
import enum

from odir_model_advanced import Advanced
from odir_model_googlenet import GoogleNet
from odir_model_vggnet import VggNet
from odir_model_inception_v1 import InceptionV1
from odir_model_vgg16 import Vgg16


class ModelTypes(enum.Enum):
vgg_net = 1
google_net = 2
advanced = 3
vgg16 = 1
inception_v1 = 2
advanced_testing = 3


class Factory:

def __init__(self, input_shape):
self.Makers = {
ModelTypes.vgg_net: VggNet(input_shape),
ModelTypes.google_net: GoogleNet(input_shape),
ModelTypes.advanced: Advanced(input_shape)
ModelTypes.vgg16: Vgg16(input_shape),
ModelTypes.inception_v1: InceptionV1(input_shape),
ModelTypes.advanced_testing: Advanced(input_shape)
}

def compile(self, model_type):
Expand Down
6 changes: 4 additions & 2 deletions odir_model_googlenet.py → odir_model_inception_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from odir_model_base import ModelBase


class GoogleNet(ModelBase):
class InceptionV1(ModelBase):

def compile(self):
input_img = Input(shape=self.input_shape)
Expand All @@ -40,8 +40,10 @@ def compile(self):
dense_3 = Dense(150, activation='relu')(dense_2)
output = Dense(8, activation='sigmoid')(dense_3)
model = Model([input_img], output)

model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

self.show_summary(model)
self.plot_summary(model, 'model_googlenet.png')
self.plot_summary(model, 'model_inception_v1.png')

return model
4 changes: 2 additions & 2 deletions odir_model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

import odir
from odir_model_factory import Factory, ModelTypes
from odir_model_googlenet import GoogleNet
from odir_model_vggnet import VggNet
from odir_model_inception_v1 import GoogleNet
from odir_model_vgg16 import VggNet

os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'
from tensorflow.keras.layers import Dense, Flatten, Conv2D, Dropout, MaxPooling2D
Expand Down
14 changes: 10 additions & 4 deletions odir_model_vggnet.py → odir_model_vgg16.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@
# limitations under the License.
# ==============================================================================
from tensorflow.keras import models, layers
from tensorflow.keras.optimizers import SGD
from odir_model_base import ModelBase


class VggNet(ModelBase):
class Vgg16(ModelBase):

def compile(self):
x = models.Sequential()


# Block 1
x.add(layers.Conv2D(input_shape=self.input_shape, filters=64,kernel_size=(3,3),padding="same", activation="relu"))

x.add(layers.Conv2D(filters=64,kernel_size=(3,3),padding="same", activation="relu"))
x.add(layers.MaxPooling2D((2, 2), strides=(2, 2)))

# Block 2
x.add(layers.Conv2D(128, kernel_size=(3,3),padding="same", activation="relu"))
x.add(layers.Conv2D(128, kernel_size=(3,3),padding="same", activation="relu"))
x.add(layers.MaxPooling2D((2, 2), strides=(2, 2)))

# Block 3
x.add(layers.Conv2D(256, kernel_size=(3,3),padding="same", activation="relu"))
x.add(layers.Conv2D(256, kernel_size=(3,3),padding="same", activation="relu"))
x.add(layers.Conv2D(256, kernel_size=(3,3),padding="same", activation="relu"))
x.add(layers.MaxPooling2D((2, 2), strides=(2, 2)))

# Block 4
x.add(layers.Conv2D(512, kernel_size=(3,3),padding="same", activation="relu"))
x.add(layers.Conv2D(512, kernel_size=(3,3),padding="same", activation="relu"))
x.add(layers.Conv2D(512, kernel_size=(3,3),padding="same", activation="relu"))
x.add(layers.MaxPooling2D((2, 2), strides=(2, 2)))

# Block 5
x.add(layers.Conv2D(512, kernel_size=(3,3),padding="same", activation="relu"))
x.add(layers.Conv2D(512, kernel_size=(3,3),padding="same", activation="relu"))
Expand All @@ -53,11 +53,17 @@ def compile(self):
x.add(layers.Dense(4096, activation='relu'))
x.add(layers.Dense(4096, activation='relu'))
x.add(layers.Dense(1000, activation='softmax'))

# Transfer learning, load previous weights
x.load_weights(r'C:\temp\vgg16_weights_tf_dim_ordering_tf_kernels.h5')

# Remove last layer
x.pop()

# Add new dense layer
x.add(layers.Dense(8, activation='sigmoid'))
x.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

self.show_summary(x)
self.plot_summary(x, 'model_vggnet.png')
return x

0 comments on commit 53fbda0

Please sign in to comment.