Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def InceptionV3(nbclasses):
- # use: model = InceptionV3()
- base_model = keras.applications.inception_v3.InceptionV3(include_top=False, weights='imagenet')
- x = base_model.output
- x = GlobalAveragePooling2D(name='avg_pool')(x)
- x = Dropout(0.4)(x)
- predictions = Dense(nbclasses, activation='softmax')(x)
- model = Model(inputs=base_model.input, outputs=predictions)
- for layer in base_model.layers:
- layer.trainable = False
- model.compile(optimizer='rmsprop',
- loss='categorical_crossentropy',
- metrics=['accuracy'])
- return model
- class InceptionV3:
- # use:
- # inc = InceptionV3()
- # model = inc.build()
- def __init__(self, nbclasses, weights='imagenet'):
- base_model = keras.applications.inception_v3.InceptionV3(include_top=False, weights=weights)
- x = base_model.output
- x = GlobalAveragePooling2D(name='avg_pool')(x)
- x = Dropout(0.4)(x)
- predictions = Dense(nbclasses, activation='softmax')(x)
- self.model = Model(inputs=base_model.input, outputs=predictions)
- for layer in base_model.layers:
- layer.trainable = False
- def build(self, metrics=None):
- if not metrics:
- metrics = ['accuracy']
- self.model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=metrics)
- return self.model
- class InceptionV3:
- # use: model = InceptionV3.build()
- @classmethod
- def build(cls, nbclasses, weights='imagenet'):
- base_model = keras.applications.inception_v3.InceptionV3(include_top=False, weights=weights)
- x = base_model.output
- x = GlobalAveragePooling2D(name='avg_pool')(x)
- x = Dropout(0.4)(x)
- predictions = Dense(nbclasses, activation='softmax')(x)
- model = Model(inputs=base_model.input, outputs=predictions)
- for layer in base_model.layers:
- layer.trainable = False
- model.compile(optimizer='rmsprop',
- loss='categorical_crossentropy',
- metrics=['accuracy'])
- return model
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement