def get_resnet101_datagen(self, test=False): if (not test): resnet101_datagen = ImageDataGenerator( horizontal_flip=True, shear_range=0.4, zoom_range=0.4, data_format=str(keras.image_data_format()), preprocessing_function=keras.applications.resnet50. preprocess_input) else: resnet101_datagen = ImageDataGenerator(data_format=str( keras.image_data_format()), preprocessing_function=piss) return resnet101_datagen
def get_inception_v3_datagen(self, test_data=False): if (not test_data): inception_v3_train_datagen = ImageDataGenerator( horizontal_flip=True, shear_range=0.4, zoom_range=0.4, data_format=str(keras.image_data_format()), preprocessing_functwion=keras.applications.inception_v3. preprocess_input) else: inception_v3_test_datagen = ImageDataGenerator( data_format=str(keras.image_data_format()), preprocessing_function=keras.applications.inception_v3. preprocess_input) return inception_v3_train_datagen
# In[79]: val_samples['lane'].value_counts() # In[82]: # dimensions of our images. img_width, img_height = 640, 480 CROP_TOP = int(200) CROP_BOTTOM = int(30) nb_train_samples = nr_train_samples nb_validation_samples = nr_val_samples batch_size = 8 if K.image_data_format() == 'channels_first': input_shape = (3, img_height, img_width) else: input_shape = (img_height, img_width, 3) inputs = Input(shape=input_shape) x = Cropping2D(cropping=((CROP_TOP, CROP_BOTTOM), (0, 0)), input_shape=input_shape)(inputs) x = GaussianNoise(0.5)(x) x = darknet_base(x) x = GlobalAveragePooling2D()(x) x = Dense(3, activation='softmax')(x) model = Model(inputs, x) #model = load_model("models/weights.358-3.57-0.64.hdf5")
def _adjust_block(p, ip, filters, weight_decay=5e-5, id=None): ''' Adjusts the input `p` to match the shape of the `input` or situations where the output number of filters needs to be changed # Arguments: p: input tensor which needs to be modified ip: input tensor whose shape needs to be matched filters: number of output filters to be matched weight_decay: l2 regularization weight id: string id # Returns: an adjusted Keras tensor ''' channel_dim = 1 if K.image_data_format() == 'channels_first' else -1 img_dim = 2 if K.image_data_format() == 'channels_first' else -2 with K.name_scope('adjust_block'): if p is None: p = ip elif p._keras_shape[img_dim] != ip._keras_shape[img_dim]: with K.name_scope('adjust_reduction_block_%s' % id): p = Activation('relu', name='adjust_relu_1_%s' % id)(p) p1 = AveragePooling2D((1, 1), strides=(2, 2), padding='valid', name='adjust_avg_pool_1_%s' % id)(p) p1 = Conv2D(filters // 2, (1, 1), padding='same', use_bias=False, kernel_regularizer=OrthLocalReg2D, name='adjust_conv_1_%s' % id, kernel_initializer='he_normal')(p1) p2 = ZeroPadding2D(padding=((0, 1), (0, 1)))(p) p2 = Cropping2D(cropping=((1, 0), (1, 0)))(p2) p2 = AveragePooling2D((1, 1), strides=(2, 2), padding='valid', name='adjust_avg_pool_2_%s' % id)(p2) p2 = Conv2D(filters // 2, (1, 1), padding='same', use_bias=False, kernel_regularizer=OrthLocalReg2D, name='adjust_conv_2_%s' % id, kernel_initializer='he_normal')(p2) p = concatenate([p1, p2], axis=channel_dim) p = BatchNormalization(name='adjust_bn_%s' % id)(p) elif p._keras_shape[channel_dim] != filters: with K.name_scope('adjust_projection_block_%s' % id): p = Activation('relu')(p) p = Conv2D(filters, (1, 1), strides=(1, 1), padding='same', name='adjust_conv_projection_%s' % id, use_bias=False, kernel_regularizer=OrthLocalReg2D, kernel_initializer='he_normal')(p) p = BatchNormalization(name='adjust_bn_%s' % id)(p) return p