这篇教程Python layers.Convolution2D方法代码示例写得很实用,希望能帮到您。
本文整理汇总了Python中keras.layers.Convolution2D方法的典型用法代码示例。如果您正苦于以下问题:Python layers.Convolution2D方法的具体用法?Python layers.Convolution2D怎么用?Python layers.Convolution2D使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块keras.layers 的用法示例。 在下文中一共展示了layers.Convolution2D方法的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。 示例1: modelB# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def modelB(): model = Sequential() model.add(Dropout(0.2, input_shape=(FLAGS.IMAGE_ROWS, FLAGS.IMAGE_COLS, FLAGS.NUM_CHANNELS))) model.add(Convolution2D(64, 8, 8, subsample=(2, 2), border_mode='same')) model.add(Activation('relu')) model.add(Convolution2D(128, 6, 6, subsample=(2, 2), border_mode='valid')) model.add(Activation('relu')) model.add(Convolution2D(128, 5, 5, subsample=(1, 1))) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Flatten()) model.add(Dense(FLAGS.NUM_CLASSES)) return model
开发者ID:sunblaze-ucb,项目名称:blackbox-attacks,代码行数:26,代码来源:mnist.py
示例2: modelC# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def modelC(): model = Sequential() model.add(Convolution2D(128, 3, 3, border_mode='valid', input_shape=(FLAGS.IMAGE_ROWS, FLAGS.IMAGE_COLS, FLAGS.NUM_CHANNELS))) model.add(Activation('relu')) model.add(Convolution2D(64, 3, 3)) model.add(Activation('relu')) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(128)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(FLAGS.NUM_CLASSES)) return model
开发者ID:sunblaze-ucb,项目名称:blackbox-attacks,代码行数:23,代码来源:mnist.py
示例3: modelF# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def modelF(): model = Sequential() model.add(Convolution2D(32, 3, 3, border_mode='valid', input_shape=(FLAGS.IMAGE_ROWS, FLAGS.IMAGE_COLS, FLAGS.NUM_CHANNELS))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Convolution2D(64, 3, 3)) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Flatten()) model.add(Dense(1024)) model.add(Activation('relu')) model.add(Dense(FLAGS.NUM_CLASSES)) return model
开发者ID:sunblaze-ucb,项目名称:blackbox-attacks,代码行数:26,代码来源:mnist.py
示例4: value_distribution_network# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def value_distribution_network(input_shape, num_atoms, action_size, learning_rate): """Model Value Distribution With States as inputs and output Probability Distributions for all Actions """ state_input = Input(shape=(input_shape)) cnn_feature = Convolution2D(32, 8, 8, subsample=(4,4), activation='relu')(state_input) cnn_feature = Convolution2D(64, 4, 4, subsample=(2,2), activation='relu')(cnn_feature) cnn_feature = Convolution2D(64, 3, 3, activation='relu')(cnn_feature) cnn_feature = Flatten()(cnn_feature) cnn_feature = Dense(512, activation='relu')(cnn_feature) distribution_list = [] for i in range(action_size): distribution_list.append(Dense(num_atoms, activation='softmax')(cnn_feature)) model = Model(input=state_input, output=distribution_list) adam = Adam(lr=learning_rate) model.compile(loss='categorical_crossentropy',optimizer=adam) return model
开发者ID:flyyufelix,项目名称:C51-DDQN-Keras,代码行数:25,代码来源:networks.py
示例5: conv2d_bn# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def conv2d_bn(x, nb_filter, nb_row, nb_col, border_mode='same', subsample=(1, 1), name=None): '''Utility function to apply conv + BN. ''' if name is not None: bn_name = name + '_bn' conv_name = name + '_conv' else: bn_name = None conv_name = None if K.image_dim_ordering() == 'th': bn_axis = 1 else: bn_axis = 3 x = Convolution2D(nb_filter, nb_row, nb_col, subsample=subsample, activation='relu', border_mode=border_mode, name=conv_name)(x) x = BatchNormalization(axis=bn_axis, name=bn_name)(x) return x
示例6: learnConcatRealImagBlock# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def learnConcatRealImagBlock(I, filter_size, featmaps, stage, block, convArgs, bnArgs, d): """Learn initial imaginary component for input.""" conv_name_base = 'res'+str(stage)+block+'_branch' bn_name_base = 'bn' +str(stage)+block+'_branch' O = BatchNormalization(name=bn_name_base+'2a', **bnArgs)(I) O = Activation(d.act)(O) O = Convolution2D(featmaps[0], filter_size, name = conv_name_base+'2a', padding = 'same', kernel_initializer = 'he_normal', use_bias = False, kernel_regularizer = l2(0.0001))(O) O = BatchNormalization(name=bn_name_base+'2b', **bnArgs)(O) O = Activation(d.act)(O) O = Convolution2D(featmaps[1], filter_size, name = conv_name_base+'2b', padding = 'same', kernel_initializer = 'he_normal', use_bias = False, kernel_regularizer = l2(0.0001))(O) return O
开发者ID:ChihebTrabelsi,项目名称:deep_complex_networks,代码行数:27,代码来源:training.py
示例7: build_policy_and_value_networks# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def build_policy_and_value_networks(num_actions, agent_history_length, resized_width, resized_height): with tf.device("/cpu:0"): state = tf.placeholder("float", [None, agent_history_length, resized_width, resized_height]) inputs = Input(shape=(agent_history_length, resized_width, resized_height,)) shared = Convolution2D(name="conv1", nb_filter=16, nb_row=8, nb_col=8, subsample=(4,4), activation='relu', border_mode='same')(inputs) shared = Convolution2D(name="conv2", nb_filter=32, nb_row=4, nb_col=4, subsample=(2,2), activation='relu', border_mode='same')(shared) shared = Flatten()(shared) shared = Dense(name="h1", output_dim=256, activation='relu')(shared) action_probs = Dense(name="p", output_dim=num_actions, activation='softmax')(shared) state_value = Dense(name="v", output_dim=1, activation='linear')(shared) policy_network = Model(input=inputs, output=action_probs) value_network = Model(input=inputs, output=state_value) p_params = policy_network.trainable_weights v_params = value_network.trainable_weights p_out = policy_network(state) v_out = value_network(state) return state, p_out, v_out, p_params, v_params
示例8: build_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def build_model(self): states_in = Input(shape=self.num_states,name='states_in') x = Convolution2D(32,(8,8),strides=(4,4),activation='relu')(states_in) x = Convolution2D(64,(4,4), strides=(2,2), activation='relu')(x) x = Convolution2D(64,(3,3), strides=(1,1), activation='relu')(x) x = Flatten(name='flattened')(x) x = Dense(512,activation='relu')(x) x = Dense(self.num_actions,activation="linear")(x) model = Model(inputs=states_in, outputs=x) self.opt = optimizers.Adam(lr=learning_rate, beta_1=0.9, beta_2=0.999, epsilon=None,decay=0.0, amsgrad=False) model.compile(loss=keras.losses.mse,optimizer=self.opt) plot_model(model,to_file='model_architecture.png',show_shapes=True) return model # Train function
开发者ID:PacktPublishing,项目名称:Intelligent-Projects-Using-Python,代码行数:20,代码来源:DQN.py
示例9: fire_module# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def fire_module(x, fire_id, squeeze=16, expand=64): s_id = 'fire' + str(fire_id) + '/' if K.image_data_format() == 'channels_first': channel_axis = 1 else: channel_axis = 3 x = Convolution2D(squeeze, (1, 1), padding='valid', name=s_id + sq1x1)(x) x = Activation('relu', name=s_id + relu + sq1x1)(x) left = Convolution2D(expand, (1, 1), padding='valid', name=s_id + exp1x1)(x) left = Activation('relu', name=s_id + relu + exp1x1)(left) right = Convolution2D(expand, (3, 3), padding='same', name=s_id + exp3x3)(x) right = Activation('relu', name=s_id + relu + exp3x3)(right) x = concatenate([left, right], axis=channel_axis, name=s_id + 'concat') return x# Original SqueezeNet from paper.
开发者ID:OlafenwaMoses,项目名称:Model-Playgrounds,代码行数:24,代码来源:squeezenet.py
示例10: drqn# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def drqn(input_shape, action_size, learning_rate): model = Sequential() model.add(TimeDistributed(Convolution2D(32, 8, 8, subsample=(4,4), activation='relu'), input_shape=(input_shape))) model.add(TimeDistributed(Convolution2D(64, 4, 4, subsample=(2,2), activation='relu'))) model.add(TimeDistributed(Convolution2D(64, 3, 3, activation='relu'))) model.add(TimeDistributed(Flatten())) # Use all traces for training #model.add(LSTM(512, return_sequences=True, activation='tanh')) #model.add(TimeDistributed(Dense(output_dim=action_size, activation='linear'))) # Use last trace for training model.add(LSTM(512, activation='tanh')) model.add(Dense(output_dim=action_size, activation='linear')) adam = Adam(lr=learning_rate) model.compile(loss='mse',optimizer=adam) return model
开发者ID:flyyufelix,项目名称:VizDoom-Keras-RL,代码行数:22,代码来源:networks.py
示例11: a2c_lstm# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def a2c_lstm(input_shape, action_size, value_size, learning_rate): """Actor and Critic Network share convolution layers with LSTM """ state_input = Input(shape=(input_shape)) # 4x64x64x3 x = TimeDistributed(Convolution2D(32, 8, 8, subsample=(4,4), activation='relu'))(state_input) x = TimeDistributed(Convolution2D(64, 4, 4, subsample=(2,2), activation='relu'))(x) x = TimeDistributed(Convolution2D(64, 3, 3, activation='relu'))(x) x = TimeDistributed(Flatten())(x) x = LSTM(512, activation='tanh')(x) # Actor Stream actor = Dense(action_size, activation='softmax')(x) # Critic Stream critic = Dense(value_size, activation='linear')(x) model = Model(input=state_input, output=[actor, critic]) adam = Adam(lr=learning_rate, clipnorm=1.0) model.compile(loss=['categorical_crossentropy', 'mse'], optimizer=adam, loss_weights=[1., 1.]) return model
开发者ID:flyyufelix,项目名称:VizDoom-Keras-RL,代码行数:26,代码来源:networks.py
示例12: build_cnn_to_lstm_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def build_cnn_to_lstm_model(self, input_shape, optimizer=Adam(lr=1e-6, decay=1e-5)): model = Sequential() model.add(TimeDistributed(Convolution2D(16, 3, 3), input_shape=input_shape)) model.add(TimeDistributed(Activation('relu'))) model.add(TimeDistributed(Convolution2D(16, 3, 3))) model.add(TimeDistributed(Activation('relu'))) model.add(TimeDistributed(MaxPooling2D(pool_size=(2, 2)))) model.add(TimeDistributed(Dropout(0.2))) model.add(TimeDistributed(Flatten())) model.add(TimeDistributed(Dense(200))) model.add(TimeDistributed(Dense(50, name="first_dense"))) model.add(LSTM(20, return_sequences=False, name="lstm_layer")) model.add(Dense(2, activation='softmax')) model.compile(loss='categorical_crossentropy', optimizer=optimizer) self.model = model
开发者ID:Ekim-Yurtsever,项目名称:DeepTL-Lane-Change-Classification,代码行数:21,代码来源:models.py
示例13: test_unsupported_variational_deconv# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def test_unsupported_variational_deconv(self): from keras.layers import Input, Lambda, Convolution2D, Flatten, Dense x = Input(shape=(8, 8, 3)) conv_1 = Convolution2D(4, 2, 2, border_mode="same", activation="relu")(x) flat = Flatten()(conv_1) hidden = Dense(10, activation="relu")(flat) z_mean = Dense(10)(hidden) z_log_var = Dense(10)(hidden) def sampling(args): z_mean, z_log_var = args return z_mean + z_log_var z = Lambda(sampling, output_shape=(10,))([z_mean, z_log_var]) model = Model([x], [z]) spec = keras.convert(model, ["input"], ["output"]).get_spec()
示例14: get_tutorial_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def get_tutorial_model(): model = Sequential() model.add(Convolution2D(32, 3, 3, input_shape=(150, 150, 3))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2), dim_ordering='tf')) model.add(Convolution2D(32, 3, 3)) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2), dim_ordering='tf')) model.add(Convolution2D(64, 3, 3)) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2), dim_ordering='tf')) # the model so far outputs 3D feature maps (height, width, features) model.add(Flatten()) # this converts our 3D feature maps to 1D feature vectors model.add(Dense(64)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(1)) model.add(Activation('sigmoid')) return model
开发者ID:johnmartinsson,项目名称:bird-species-classification,代码行数:26,代码来源:tutorial.py
示例15: get_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def get_model(): model = Sequential() model.add(Convolution2D(32, 3, 3, input_shape=(150, 150, 3))) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2), dim_ordering='tf')) model.add(Convolution2D(32, 3, 3)) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2), dim_ordering='tf')) model.add(Convolution2D(64, 3, 3)) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2), dim_ordering='tf')) # the model so far outputs 3D feature maps (height, width, features) model.add(Flatten()) # this converts our 3D feature maps to 1D feature vectors model.add(Dense(64)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(1)) model.add(Activation('sigmoid')) return model
开发者ID:johnmartinsson,项目名称:bird-species-classification,代码行数:26,代码来源:tutorial.py
示例16: discriminator_network# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def discriminator_network(input_image_tensor): """ The discriminator network, Dφ, contains 5 convolution layers and 2 max-pooling layers. :param input_image_tensor: Input tensor corresponding to an image, either real or refined. :return: Output tensor that corresponds to the probability of whether an image is real or refined. """ x = layers.Convolution2D(96, 3, 3, border_mode='same', subsample=(2, 2), activation='relu')(input_image_tensor) x = layers.Convolution2D(64, 3, 3, border_mode='same', subsample=(2, 2), activation='relu')(x) x = layers.MaxPooling2D(pool_size=(3, 3), border_mode='same', strides=(1, 1))(x) x = layers.Convolution2D(32, 3, 3, border_mode='same', subsample=(1, 1), activation='relu')(x) x = layers.Convolution2D(32, 1, 1, border_mode='same', subsample=(1, 1), activation='relu')(x) x = layers.Convolution2D(2, 1, 1, border_mode='same', subsample=(1, 1), activation='relu')(x) # here one feature map corresponds to `is_real` and the other to `is_refined`, # and the custom loss function is then `tf.nn.sparse_softmax_cross_entropy_with_logits` return layers.Reshape((-1, 2))(x)
开发者ID:mjdietzx,项目名称:SimGAN,代码行数:19,代码来源:sim-gan.py
示例17: build_cnn# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def build_cnn(input_shape, nb_filters, filter_size, pool_size): model = Sequential() model.add(Convolution2D(nb_filters, filter_size[0], filter_size[1], border_mode='valid', input_shape=input_shape)) model.add(Activation('relu')) model.add(Convolution2D(nb_filters, filter_size[0], filter_size[1])) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=pool_size)) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(128)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(nb_classes)) model.add(Activation('softmax')) return model
开发者ID:aidiary,项目名称:keras-examples,代码行数:27,代码来源:mnist.py
示例18: identity_block# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def identity_block(input_tensor, kernel_size, filters, stage, block): nb_filter1, nb_filter2, nb_filter3 = filters bn_axis = 1 conv_name_base = 'res' + str(stage) + block + '_branch' bn_name_base = 'bn' + str(stage) + block + '_branch' x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2a')(x) x = Activation('relu')(x) x = Convolution2D(nb_filter2, kernel_size, kernel_size, border_mode='same', name=conv_name_base + '2b')(x) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2b')(x) x = Activation('relu')(x) x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2c')(x) x = merge([x, input_tensor], mode='sum') x = Activation('relu')(x) return x
示例19: conv_block_atrous# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def conv_block_atrous(input_tensor, kernel_size, filters, stage, block, atrous_rate=(2, 2)): nb_filter1, nb_filter2, nb_filter3 = filters bn_axis = 1 conv_name_base = 'res' + str(stage) + block + '_branch' bn_name_base = 'bn' + str(stage) + block + '_branch' x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2a')(x) x = Activation('relu')(x) x = AtrousConvolution2D(nb_filter2, kernel_size, kernel_size, border_mode='same', atrous_rate=atrous_rate, name=conv_name_base + '2b')(x) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2b')(x) x = Activation('relu')(x) x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2c')(x) shortcut = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '1')(input_tensor) shortcut = BatchNormalization(axis=bn_axis, name=bn_name_base + '1')(shortcut) x = merge([x, shortcut], mode='sum') x = Activation('relu')(x) return x
示例20: identity_block_atrous# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def identity_block_atrous(input_tensor, kernel_size, filters, stage, block, atrous_rate=(2, 2)): nb_filter1, nb_filter2, nb_filter3 = filters bn_axis = 1 conv_name_base = 'res' + str(stage) + block + '_branch' bn_name_base = 'bn' + str(stage) + block + '_branch' x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2a')(x) x = Activation('relu')(x) x = AtrousConvolution2D(nb_filter2, kernel_size, kernel_size, atrous_rate=atrous_rate, border_mode='same', name=conv_name_base + '2b')(x) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2b')(x) x = Activation('relu')(x) x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2c')(x) x = merge([x, input_tensor], mode='sum') x = Activation('relu')(x) return x
示例21: conv_2d# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def conv_2d(filters, kernel_shape, strides, padding, input_shape=None): """ Defines the right convolutional layer according to the version of Keras that is installed. :param filters: (required integer) the dimensionality of the output space (i.e. the number output of filters in the convolution) :param kernel_shape: (required tuple or list of 2 integers) specifies the strides of the convolution along the width and height. :param padding: (required string) can be either 'valid' (no padding around input or feature map) or 'same' (pad to ensure that the output feature map size is identical to the layer input) :param input_shape: (optional) give input shape if this is the first layer of the model :return: the Keras layer """ if LooseVersion(keras.__version__) >= LooseVersion('2.0.0'): if input_shape is not None: return Conv2D(filters=filters, kernel_size=kernel_shape, strides=strides, padding=padding, input_shape=input_shape) else: return Conv2D(filters=filters, kernel_size=kernel_shape, strides=strides, padding=padding) else: if input_shape is not None: return Convolution2D(filters, kernel_shape[0], kernel_shape[1], subsample=strides, border_mode=padding, input_shape=input_shape) else: return Convolution2D(filters, kernel_shape[0], kernel_shape[1], subsample=strides, border_mode=padding)
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:35,代码来源:utils_keras.py
示例22: build_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def build_model(n_classes): if K.image_dim_ordering() == 'th': input_shape = (1, N_MEL_BANDS, SEGMENT_DUR) channel_axis = 1 else: input_shape = (N_MEL_BANDS, SEGMENT_DUR, 1) channel_axis = 3 melgram_input = Input(shape=input_shape) m_sizes = [50, 70] n_sizes = [1, 3, 5] n_filters = [128, 64, 32] maxpool_const = 4 layers = list() for m_i in m_sizes: for i, n_i in enumerate(n_sizes): x = Convolution2D(n_filters[i], m_i, n_i, border_mode='same', init='he_normal', W_regularizer=l2(1e-5), name=str(n_i)+'_'+str(m_i)+'_'+'conv')(melgram_input) x = BatchNormalization(axis=channel_axis, mode=0, name=str(n_i)+'_'+str(m_i)+'_'+'bn')(x) x = ELU()(x) x = MaxPooling2D(pool_size=(N_MEL_BANDS, SEGMENT_DUR/maxpool_const), name=str(n_i)+'_'+str(m_i)+'_'+'pool')(x) x = Flatten(name=str(n_i)+'_'+str(m_i)+'_'+'flatten')(x) layers.append(x) x = merge(layers, mode='concat', concat_axis=channel_axis) x = Dropout(0.5)(x) x = Dense(n_classes, init='he_normal', W_regularizer=l2(1e-5), activation='softmax', name='prediction')(x) model = Model(melgram_input, x) return model
示例23: arch# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def arch(inp): con1 = Convolution2D(32, 3, 3, border_mode='valid', activation = 'relu', subsample=(2,2)) con2 = Convolution2D(32, 3, 3, activation = 'relu', subsample=(2,2)) fla1 = Flatten() den1 = Dense(128, activation = 'relu') den2 = Dense(nb_classes, activation = 'softmax') out = den2(den1(fla1(con2(con1(inp))))) # fla1 = Flatten() # den1 = Dense(128, activation = 'relu') # den2 = Dense(128, activation = 'relu') # den3 = Dense(nb_classes, activation = 'softmax') # out = den3(den2(den1(fla1(inp)))) return out
示例24: DarknetConv2D# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def DarknetConv2D(*args, **kwargs): """Wrapper to set Darknet weight regularizer for Convolution2D.""" darknet_conv_kwargs = {'W_regularizer': l2(5e-4)} darknet_conv_kwargs.update(kwargs) return _DarknetConv2D(*args, **darknet_conv_kwargs)
示例25: DarknetConv2D_BN_Leaky# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def DarknetConv2D_BN_Leaky(*args, **kwargs): """Darknet Convolution2D followed by BatchNormalization and LeakyReLU.""" return compose( DarknetConv2D(*args, **kwargs), BatchNormalization(), LeakyReLU(alpha=0.1))
示例26: create_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def create_model(): model = Sequential() model.add(Convolution2D(32, 3, 3, border_mode='valid', input_shape=(100, 100, 3))) model.add(Activation('relu')) model.add(Convolution2D(32, 3, 3)) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.25)) model.add(Convolution2D(64, 3, 3, border_mode='valid')) model.add(Activation('relu')) model.add(Convolution2D(64, 3, 3)) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(256)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(2)) model.add(Activation('softmax')) return model
开发者ID:JasonDoingGreat,项目名称:Convolutional-Networks-for-Stock-Predicting,代码行数:31,代码来源:cnn_main.py
示例27: get_logit_cnn_layers# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def get_logit_cnn_layers(nb_units, p, wd, nb_classes, layers = [], dropout = False): # number of convolutional filters to use nb_filters = 32 # size of pooling area for max pooling pool_size = (2, 2) # convolution kernel size kernel_size = (3, 3) if dropout == 'MC': D = Dropout_mc if dropout == 'pW': D = pW if dropout == 'none': D = Identity layers.append(Convolution2D(nb_filters, kernel_size[0], kernel_size[1], border_mode='valid', W_regularizer=l2(wd))) layers.append(Activation('relu')) layers.append(Convolution2D(nb_filters, kernel_size[0], kernel_size[1], W_regularizer=l2(wd))) layers.append(Activation('relu')) layers.append(MaxPooling2D(pool_size=pool_size)) layers.append(Flatten()) layers.append(D(p)) layers.append(Dense(nb_units, W_regularizer=l2(wd))) layers.append(Activation('relu')) layers.append(D(p)) layers.append(Dense(nb_classes, W_regularizer=l2(wd))) return layers
示例28: identity_block# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def identity_block(input_tensor, kernel_size, filters, stage, block): '''The identity_block is the block that has no conv layer at shortcut # Arguments input_tensor: input tensor kernel_size: defualt 3, the kernel size of middle conv layer at main path filters: list of integers, the nb_filters of 3 conv layer at main path stage: integer, current stage label, used for generating layer names block: 'a','b'..., current block label, used for generating layer names ''' nb_filter1, nb_filter2, nb_filter3 = filters if K.image_dim_ordering() == 'tf': bn_axis = 3 else: bn_axis = 1 conv_name_base = 'res' + str(stage) + block + '_branch' bn_name_base = 'bn' + str(stage) + block + '_branch' x = Convolution2D(nb_filter1, 1, 1, name=conv_name_base + '2a')(input_tensor) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2a')(x) x = Activation('relu')(x) x = Convolution2D(nb_filter2, kernel_size, kernel_size, border_mode='same', name=conv_name_base + '2b')(x) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2b')(x) x = Activation('relu')(x) x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2c')(x) x = merge([x, input_tensor], mode='sum') x = Activation('relu')(x) return x
开发者ID:ChunML,项目名称:DeepLearning,代码行数:35,代码来源:resnet50.py
示例29: conv_block# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Convolution2D [as 别名]def conv_block(input_tensor, kernel_size, filters, stage, block, strides=(2, 2)): '''conv_block is the block that has a conv layer at shortcut # Arguments input_tensor: input tensor kernel_size: defualt 3, the kernel size of middle conv layer at main path filters: list of integers, the nb_filters of 3 conv layer at main path stage: integer, current stage label, used for generating layer names block: 'a','b'..., current block label, used for generating layer names Note that from stage 3, the first conv layer at main path is with subsample=(2,2) And the shortcut should have subsample=(2,2) as well ''' nb_filter1, nb_filter2, nb_filter3 = filters if K.image_dim_ordering() == 'tf': bn_axis = 3 else: bn_axis = 1 conv_name_base = 'res' + str(stage) + block + '_branch' bn_name_base = 'bn' + str(stage) + block + '_branch' x = Convolution2D(nb_filter1, 1, 1, subsample=strides, name=conv_name_base + '2a')(input_tensor) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2a')(x) x = Activation('relu')(x) x = Convolution2D(nb_filter2, kernel_size, kernel_size, border_mode='same', name=conv_name_base + '2b')(x) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2b')(x) x = Activation('relu')(x) x = Convolution2D(nb_filter3, 1, 1, name=conv_name_base + '2c')(x) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2c')(x) shortcut = Convolution2D(nb_filter3, 1, 1, subsample=strides, name=conv_name_base + '1')(input_tensor) shortcut = BatchNormalization(axis=bn_axis, name=bn_name_base + '1')(shortcut) x = merge([x, shortcut], mode='sum') x = Activation('relu')(x) return x
开发者ID:ChunML,项目名称:DeepLearning,代码行数:43,代码来源:resnet50.py
|