Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | None | 0 0
  1. def InceptionV3(nbclasses):
  2.     # use: model = InceptionV3()
  3.     base_model = keras.applications.inception_v3.InceptionV3(include_top=False, weights='imagenet')
  4.     x = base_model.output
  5.     x = GlobalAveragePooling2D(name='avg_pool')(x)
  6.     x = Dropout(0.4)(x)
  7.     predictions = Dense(nbclasses, activation='softmax')(x)
  8.     model = Model(inputs=base_model.input, outputs=predictions)
  9.  
  10.     for layer in base_model.layers:
  11.         layer.trainable = False
  12.  
  13.     model.compile(optimizer='rmsprop',
  14.                   loss='categorical_crossentropy',
  15.                   metrics=['accuracy'])
  16.  
  17.     return model
  18.  
  19.  
  20. class InceptionV3:
  21.     # use:
  22.     # inc = InceptionV3()
  23.     # model = inc.build()
  24.     def __init__(self, nbclasses, weights='imagenet'):
  25.         base_model = keras.applications.inception_v3.InceptionV3(include_top=False, weights=weights)
  26.         x = base_model.output
  27.         x = GlobalAveragePooling2D(name='avg_pool')(x)
  28.         x = Dropout(0.4)(x)
  29.         predictions = Dense(nbclasses, activation='softmax')(x)
  30.         self.model = Model(inputs=base_model.input, outputs=predictions)
  31.  
  32.         for layer in base_model.layers:
  33.             layer.trainable = False
  34.  
  35.     def build(self, metrics=None):
  36.         if not metrics:
  37.             metrics = ['accuracy']
  38.         self.model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=metrics)
  39.         return self.model
  40.  
  41.  
  42. class InceptionV3:
  43.     # use: model = InceptionV3.build()
  44.     @classmethod
  45.     def build(cls, nbclasses, weights='imagenet'):
  46.         base_model = keras.applications.inception_v3.InceptionV3(include_top=False, weights=weights)
  47.         x = base_model.output
  48.         x = GlobalAveragePooling2D(name='avg_pool')(x)
  49.         x = Dropout(0.4)(x)
  50.         predictions = Dense(nbclasses, activation='softmax')(x)
  51.         model = Model(inputs=base_model.input, outputs=predictions)
  52.  
  53.         for layer in base_model.layers:
  54.             layer.trainable = False
  55.  
  56.         model.compile(optimizer='rmsprop',
  57.                       loss='categorical_crossentropy',
  58.                       metrics=['accuracy'])
  59.  
  60.         return model
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement