Exemplo n.º 1
0
def create_model(trainable=False):
    #model = vgg16.VGG16(include_top=False, weights='imagenet',input_shape=(IMAGE_SIZE_H,IMAGE_SIZE_W , 3), pooling='None')
    model = resnet.ResNet50(include_top=False,
                            weights='imagenet',
                            input_shape=(360, 640, 3))

    for layer in model.layers:
        layer.trainable = False

    model.layers[-1].trainable = True
    model.layers[-2].trainable = True
    model.layers[-3].trainable = True
    model.layers[-4].trainable = True
    model.layers[-5].trainable = True
    model.layers[-6].trainable = True
    model.layers[-7].trainable = True
    model.layers[-8].trainable = True
    model.layers[-9].trainable = True
    model.layers[-10].trainable = True
    model.layers[-11].trainable = True

    out = model.layers[-1].output
    x = GlobalAveragePooling2D()(out)
    x = Dense(4, activation='linear')(x)

    return Model(inputs=model.input, outputs=x)
Exemplo n.º 2
0
def get_base_extractor():
    be = resnet.ResNet50(include_top=False,
                         weights='imagenet',
                         input_shape=config.IMAGE_SHAPE + (3, ))
    for layer in be.layers:
        if layer.name == "conv5_block1_out":
            layer.trainable = True

        layer.trainable = False
    return be
Exemplo n.º 3
0
 def ResNet50(self,output_layer='avg_pool'):
     """ResNet50 - avg_pool - output_shape = 2048
     """
     base_model = resnet.ResNet50(weights='imagenet')
     _model = Model(input=base_model.input, output=base_model.get_layer(output_layer).output)
     _model.summary()
     self.imageSize = (224,224)
     self.model = _model
     self.preinput = resnet.preprocess_input
     return self._process()
Exemplo n.º 4
0
    def __init__(self, input_shape, output_units, filepath='best_model.hdf5'):
        """input_shape: (height, width)"""
        self.input_shape = input_shape
        self.height_pad = 32-input_shape[0]
        self.width_pad = 32-input_shape[1]
        self.height, self.width = (32, 32)
        self.output_units = output_units

        ## input layer
        self.input_layer = Input(
            (
                self.height,
                self.width,
                1
            )
        )

        self.base_model = resnet.ResNet50(
            weights=None,
            include_top=False,
            input_shape=(32, 32, 1)
        )(self.input_layer)
        self.flatten_layer = Flatten()(self.base_model)

        ########################################################################
        # fully connected layers
        ########################################################################
        dense_layer1 = Dense(
            units=256,
            activation='relu'
        )(self.flatten_layer)
        self.dense_layer1 = Dropout(0.4)(dense_layer1)

        dense_layer2 = Dense(
            units=128,
            activation='relu'
        )(self.dense_layer1)
        self.dense_layer2 = Dropout(0.4)(dense_layer2)

        self.output_layer = Dense(
            units=self.output_units,
            activation='softmax'
        )(self.dense_layer2)

        self.model = Model(inputs=self.input_layer, outputs=self.output_layer)
        self.adam = Adam(lr=0.001, decay=1e-06)
        self.model.compile(loss='categorical_crossentropy', optimizer=self.adam, metrics=['accuracy'])
        self.model.summary()
        abspath = os.path.abspath('.')
        self.filepath = os.path.abspath(os.path.join(abspath,filepath))
        checkpoint = ModelCheckpoint(self.filepath, monitor='accuracy', verbose=1, save_best_only=True, mode='max')
        self.callbacks_list = [checkpoint]
Exemplo n.º 5
0
def create_model(trainable=False):
    model = resnet.ResNet50(include_top=False,
                            weights='imagenet',
                            input_shape=(360, 640, 3),
                            pooling='None')
    for layer in model.layers:
        layer.trainable = False

    out = model.layers[-1].output
    x = GlobalAveragePooling2D()(out)
    x = Dense(4, activation='sigmoid')(x)

    return Model(inputs=model.input, outputs=x)
Exemplo n.º 6
0
def MVCNN():
    resnet = rn.ResNet50()

    model = Sequential()
    model.add(Convolution2D(512, kernel_size=(1,1), stride=1, padding='valid', dilation_rate=1, use_bias=True, activation='relu', input_shape=(1,28,28)))
    mo
    model.add(Convolution2D(32, 3, 3, kernel_size=(3,3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(Dropout(0.25))
    model.add(Flatten())
    model.add(Dense(128, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(17, activation='softmax'))
Exemplo n.º 7
0
    def _default_resnet50(self):
        input_image = layers.Input(name='image',
                                   shape=(None, None, 3),
                                   dtype=self.compute_dtype)
        base_model = resnet.ResNet50(input_tensor=input_image,
                                     include_top=False,
                                     weights='imagenet')

        end_points = ['conv1_relu', 'conv2_block3_out', 'conv5_block3_out']
        out_layers = [
            base_model.get_layer(name=name_idx).output
            for name_idx in end_points
        ]

        return Model(inputs=input_image, outputs=out_layers)
    def ResNet50(self, output_layer='avg_pool'):
        """ResNet50 - avg_pool - output_shape = 2048. Tensorflow pretrain model.

        Keyword Arguments:
            output_layer {str} -- The layer of ResNet50 architecture (default: {'fc2'})

        Returns:
            [Feature Object] -- Return Feature Object from function _process. 
        """
        self.method = 'resnet50'
        self._framework = 'tensorflow'
        self._device = '/device:' + self._device
        base_model = resnet.ResNet50(weights='imagenet')
        _model = Model(input=base_model.input,
                       output=base_model.get_layer(output_layer).output)
        _model.summary()
        self.imageSize = (224, 224)
        self.model = _model
        self.preinput = resnet.preprocess_input
        return self._process()
Exemplo n.º 9
0
# In[ ]:

x_input1 = []
x_input2 = []
for i in range(m_test):
    x_input1.append(np.asarray(test_df['AP'][i]))
    x_input2.append(np.asarray(test_df['LAT'][i]))

x_input1 = np.array(x_input1)
x_input2 = np.array(x_input2)

# In[ ]:

base_model = resnet.ResNet50(include_top=False,
                             weights='imagenet',
                             layers=1,
                             input_shape=(512, 256, 3),
                             pooling=None)

preds1 = base_model.predict(x_input1)
#print(preds1.shape)
preds2 = base_model.predict(x_input2)
#print(preds2.shape)

# In[ ]:

predictions = model.predict([preds1, preds2])

# In[ ]:

label_pred = (np.array(predictions > 0.5, dtype=np.int))