def __init__( self, architecture: CompiledArchitecture, data: DataSetSplit, epochs: int, patience: int, ) -> None: """ # Arguments epochs: - 0 for automatically stopping when training yields no improvements for a specified number of epochs - any positive integer for a set number of epochs """ self._architecture: CompiledArchitecture = architecture self._data: DataSetSplit = data self._names: ModelSplitName = ModelSplitName( architecture.name(), data.name(), epochs, patience, ) self._kmodel: keras.models.Model = None self._total_epochs: int = epochs self._patience: int = patience self._is_best: bool = False self._status: TrainingStatusData = None self._res = Resolution(190) self._batch = 10
def create(self, res: Resolution, classes: Optional[int]) -> Model: """ Creates a keras.models.Model object. """ if type(classes) is not int: raise ValueError(classes) return VGG16( include_top=True, weights=None, input_tensor=Input(res.hwc()), classes=classes, )
def create(self, res: Resolution, classes: Optional[int]) -> Model: """ Creates a keras.models.Model object. """ img_input = Input(res.hwc()) x = ResNet101( include_top=True, weights=None, input_tensor=img_input, ) x = Dense(1, activation='relu', name='predictions')(x.output) model = Model(img_input, x, name='resnet101a') return model
def create(self, res: Resolution, classes: Optional[int]) -> Model: """ Creates a keras.models.Model object. """ if type(classes) is not int: raise ValueError(classes) base = VGG16( include_top=False, weights='imagenet', input_shape=res.hwc(), ) base.trainable = False x = Flatten(name='flatten')(base.output) x = Dense(4096, activation='relu', name='fc1')(x) x = Dense(4096, activation='relu', name='fc2')(x) x = Dense(classes, activation='softmax', name='predictions')(x) model = Model(base.input, x, name='vgg16pt') return model
def create(self, res: Resolution, classes: Optional[int]) -> Model: """ Creates a keras.models.Model object. """ if type(classes) is not int: raise ValueError(classes) img_input = Input(res.hwc()) # Block 1 x = Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv1')(img_input) x = Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv2')(x) x = MaxPooling2D((2, 2), strides=(2, 2), name='block1_pool')(x) # Block 2 x = Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv1')(x) x = Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv2')(x) x = MaxPooling2D((2, 2), strides=(2, 2), name='block2_pool')(x) # Block 3 x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv1')(x) x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv2')(x) x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv3')(x) x = MaxPooling2D((2, 2), strides=(2, 2), name='block3_pool')(x) # Block 4 x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv1')(x) x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv2')(x) x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv3')(x) x = MaxPooling2D((2, 2), strides=(2, 2), name='block4_pool')(x) # Block 5 x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv1')(x) x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv2')(x) x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv3')(x) x = MaxPooling2D((2, 2), strides=(2, 2), name='block5_pool')(x) # Classification block x = Flatten(name='flatten')(x) x = Dense(4096, activation='relu', name='fc1')(x) x = Dense(4096, activation='relu', name='fc2')(x) x = Dense(classes, activation='softmax', name='predictions')(x) model = Model(img_input, x, name='vgg16') return model
def create(self, res: Resolution, classes: Optional[int]) -> Model: """ Returns a Keras Model object. """ img_input = Input(res.hwc()) # Block 1 x = Conv2D(filters=96, kernel_size=(11, 11), strides=4, activation='relu', padding='same', name='block1_conv1')(img_input) x = BatchNormalization()(x) x = MaxPooling2D((3, 3), strides=(2, 2), name='block1_pool')(x) # Block 2 x = Conv2D( filters=256, kernel_size=(5, 5), # strides=4, activation='relu', padding='same', name='block2_conv1')(x) x = BatchNormalization()(x) x = MaxPooling2D((3, 3), strides=(2, 2), name='block2_pool')(x) # Block 3 x = Conv2D( filters=384, kernel_size=(3, 3), # strides=4, activation='relu', padding='same', name='block3_conv1')(x) # Block 4 x = Conv2D( filters=384, kernel_size=(3, 3), # strides=4, activation='relu', padding='same', name='block4_conv1')(x) # Block 5 x = Conv2D( filters=256, kernel_size=(3, 3), # strides=4, activation='relu', padding='same', name='block5_conv1')(x) x = MaxPooling2D((3, 3), strides=(2, 2), name='block5_pool')(x) # Classification block x = Flatten(name='flatten')(x) x = Dense(4096, activation='relu', name='fc1')(x) x = Dense(4096, activation='relu', name='fc2')(x) x = Dense(classes, activation='softmax', name='predictions')(x) model = Model(img_input, x, name='smi13a') return model