您当前的位置:首页 > IT编程 > Keras
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:Python layers.Flatten方法代码示例

51自学网 2020-12-01 11:08:44
  Keras
这篇教程Python layers.Flatten方法代码示例写得很实用,希望能帮到您。

本文整理汇总了Python中keras.layers.Flatten方法的典型用法代码示例。如果您正苦于以下问题:Python layers.Flatten方法的具体用法?Python layers.Flatten怎么用?Python layers.Flatten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块keras.layers的用法示例。

在下文中一共展示了layers.Flatten方法的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _save

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def _save(model, base_model, layers, labels, random_seed, checkpoints_dir):    from keras.layers import Flatten, Dense    from keras import Model    nclasses = len(labels)    x = Flatten()(base_model.output)    x = _makenet(x, layers, dropout=None, random_seed=random_seed)    predictions = Dense(nclasses, activation="softmax", name="predictions")(x)    model_final = Model(inputs=base_model.input, outputs=predictions)    for i in range(layers - 1):        weights = model.get_layer(name='dense_layer_{}'.format(i)).get_weights()        model_final.get_layer(name='dense_layer_{}'.format(i)).set_weights(weights)    weights = model.get_layer(name='predictions').get_weights()    model_final.get_layer(name='predictions').set_weights(weights)    model_final.save(os.path.join(checkpoints_dir, "model.h5"))    with open(os.path.join(checkpoints_dir, "labels.txt"), "w") as f:        f.write("/n".join(labels))    return model_final 
开发者ID:mme,项目名称:vergeml,代码行数:22,代码来源:imagenet.py


示例2: __init__

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def __init__(self, model_path=None):        if model_path is not None:            self.model = self.load_model(model_path)        else:            # VGG16 last conv features            inputs = Input(shape=(7, 7, 512))            x = Convolution2D(128, 1, 1)(inputs)            x = Flatten()(x)            # Cls head            h_cls = Dense(256, activation='relu', W_regularizer=l2(l=0.01))(x)            h_cls = Dropout(p=0.5)(h_cls)            cls_head = Dense(20, activation='softmax', name='cls')(h_cls)            # Reg head            h_reg = Dense(256, activation='relu', W_regularizer=l2(l=0.01))(x)            h_reg = Dropout(p=0.5)(h_reg)            reg_head = Dense(4, activation='linear', name='reg')(h_reg)            # Joint model            self.model = Model(input=inputs, output=[cls_head, reg_head]) 
开发者ID:wiseodd,项目名称:cnn-levelset,代码行数:23,代码来源:localizer.py


示例3: build_discriminator

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def build_discriminator(self):        model = Sequential()        model.add(Conv2D(64, kernel_size=3, strides=2, input_shape=self.missing_shape, padding="same"))        model.add(LeakyReLU(alpha=0.2))        model.add(BatchNormalization(momentum=0.8))        model.add(Conv2D(128, kernel_size=3, strides=2, padding="same"))        model.add(LeakyReLU(alpha=0.2))        model.add(BatchNormalization(momentum=0.8))        model.add(Conv2D(256, kernel_size=3, padding="same"))        model.add(LeakyReLU(alpha=0.2))        model.add(BatchNormalization(momentum=0.8))        model.add(Flatten())        model.add(Dense(1, activation='sigmoid'))        model.summary()        img = Input(shape=self.missing_shape)        validity = model(img)        return Model(img, validity) 
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:23,代码来源:context_encoder.py


示例4: build_discriminator

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def build_discriminator(self):        img = Input(shape=self.img_shape)        model = Sequential()        model.add(Conv2D(64, kernel_size=4, strides=2, padding='same', input_shape=self.img_shape))        model.add(LeakyReLU(alpha=0.8))        model.add(Conv2D(128, kernel_size=4, strides=2, padding='same'))        model.add(LeakyReLU(alpha=0.2))        model.add(InstanceNormalization())        model.add(Conv2D(256, kernel_size=4, strides=2, padding='same'))        model.add(LeakyReLU(alpha=0.2))        model.add(InstanceNormalization())        model.summary()        img = Input(shape=self.img_shape)        features = model(img)        validity = Conv2D(1, kernel_size=4, strides=1, padding='same')(features)        label = Flatten()(features)        label = Dense(self.num_classes+1, activation="softmax")(label)        return Model(img, [validity, label]) 
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:27,代码来源:ccgan.py


示例5: build_encoder

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def build_encoder(self):        model = Sequential()        model.add(Flatten(input_shape=self.img_shape))        model.add(Dense(512))        model.add(LeakyReLU(alpha=0.2))        model.add(BatchNormalization(momentum=0.8))        model.add(Dense(512))        model.add(LeakyReLU(alpha=0.2))        model.add(BatchNormalization(momentum=0.8))        model.add(Dense(self.latent_dim))        model.summary()        img = Input(shape=self.img_shape)        z = model(img)        return Model(img, z) 
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:20,代码来源:bigan.py


示例6: build_discriminator

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def build_discriminator(self):        z = Input(shape=(self.latent_dim, ))        img = Input(shape=self.img_shape)        d_in = concatenate([z, Flatten()(img)])        model = Dense(1024)(d_in)        model = LeakyReLU(alpha=0.2)(model)        model = Dropout(0.5)(model)        model = Dense(1024)(model)        model = LeakyReLU(alpha=0.2)(model)        model = Dropout(0.5)(model)        model = Dense(1024)(model)        model = LeakyReLU(alpha=0.2)(model)        model = Dropout(0.5)(model)        validity = Dense(1, activation="sigmoid")(model)        return Model([z, img], validity) 
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:20,代码来源:bigan.py


示例7: build_classifier

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def build_classifier(self):        def clf_layer(layer_input, filters, f_size=4, normalization=True):            """Classifier layer"""            d = Conv2D(filters, kernel_size=f_size, strides=2, padding='same')(layer_input)            d = LeakyReLU(alpha=0.2)(d)            if normalization:                d = InstanceNormalization()(d)            return d        img = Input(shape=self.img_shape)        c1 = clf_layer(img, self.cf, normalization=False)        c2 = clf_layer(c1, self.cf*2)        c3 = clf_layer(c2, self.cf*4)        c4 = clf_layer(c3, self.cf*8)        c5 = clf_layer(c4, self.cf*8)        class_pred = Dense(self.num_classes, activation='softmax')(Flatten()(c5))        return Model(img, class_pred) 
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:23,代码来源:pixelda.py


示例8: build_discriminators

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def build_discriminators(self):        img1 = Input(shape=self.img_shape)        img2 = Input(shape=self.img_shape)        # Shared discriminator layers        model = Sequential()        model.add(Flatten(input_shape=self.img_shape))        model.add(Dense(512))        model.add(LeakyReLU(alpha=0.2))        model.add(Dense(256))        model.add(LeakyReLU(alpha=0.2))        img1_embedding = model(img1)        img2_embedding = model(img2)        # Discriminator 1        validity1 = Dense(1, activation='sigmoid')(img1_embedding)        # Discriminator 2        validity2 = Dense(1, activation='sigmoid')(img2_embedding)        return Model(img1, validity1), Model(img2, validity2) 
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:24,代码来源:cogan.py


示例9: build_discriminator

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def build_discriminator(self):        model = Sequential()        model.add(Flatten(input_shape=self.img_shape))        model.add(Dense(512))        model.add(LeakyReLU(alpha=0.2))        model.add(Dense(256))        model.add(LeakyReLU(alpha=0.2))        model.add(Dense(1, activation='sigmoid'))        model.summary()        img = Input(shape=self.img_shape)        validity = model(img)        return Model(img, validity) 
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:18,代码来源:gan.py


示例10: encoder

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def encoder(self):        if self.E:            return self.E        inp = Input(shape = [im_size, im_size, 3])        x = d_block(inp, 1 * cha)   #64        x = d_block(x, 2 * cha)   #32        x = d_block(x, 3 * cha)   #16        x = d_block(x, 4 * cha)  #8        x = d_block(x, 8 * cha)  #4        x = d_block(x, 16 * cha, p = False)  #4        x = Flatten()(x)        x = Dense(16 * cha, kernel_initializer = 'he_normal')(x)        x = LeakyReLU(0.2)(x)        x = Dense(latent_size, kernel_initializer = 'he_normal', bias_initializer = 'zeros')(x)        self.E = Model(inputs = inp, outputs = x)        return self.E 
开发者ID:manicman1999,项目名称:Keras-BiGAN,代码行数:26,代码来源:bigan.py


示例11: build_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def build_model(x_train, num_classes):        # Reset default graph. Keras leaves old ops in the graph,        # which are ignored for execution but clutter graph        # visualization in TensorBoard.        tf.reset_default_graph()        inputs = KL.Input(shape=x_train.shape[1:], name="input_image")        x = KL.Conv2D(32, (3, 3), activation='relu', padding="same",                      name="conv1")(inputs)        x = KL.Conv2D(64, (3, 3), activation='relu', padding="same",                      name="conv2")(x)        x = KL.MaxPooling2D(pool_size=(2, 2), name="pool1")(x)        x = KL.Flatten(name="flat1")(x)        x = KL.Dense(128, activation='relu', name="dense1")(x)        x = KL.Dense(num_classes, activation='softmax', name="dense2")(x)        return KM.Model(inputs, x, "digit_classifier_model")    # Load MNIST Data 
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:21,代码来源:parallel_model.py


示例12: modelA

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def modelA():    model = Sequential()    model.add(Conv2D(64, (5, 5),                            padding='valid'))    model.add(Activation('relu'))    model.add(Conv2D(64, (5, 5)))    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,代码行数:20,代码来源:mnist.py


示例13: modelB

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [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


示例14: modelC

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [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


示例15: modelD

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def modelD():    model = Sequential()    model.add(Flatten(input_shape=(FLAGS.IMAGE_ROWS,                                   FLAGS.IMAGE_COLS,                                   FLAGS.NUM_CHANNELS)))    model.add(Dense(300, init='he_normal', activation='relu'))    model.add(Dropout(0.5))    model.add(Dense(300, init='he_normal', activation='relu'))    model.add(Dropout(0.5))    model.add(Dense(300, init='he_normal', activation='relu'))    model.add(Dropout(0.5))    model.add(Dense(300, init='he_normal', activation='relu'))    model.add(Dropout(0.5))    model.add(Dense(FLAGS.NUM_CLASSES))    return model 
开发者ID:sunblaze-ucb,项目名称:blackbox-attacks,代码行数:20,代码来源:mnist.py


示例16: test_simple_keras_udf

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def test_simple_keras_udf(self):        """ Simple Keras sequential model """        # Notice that the input layer for a image UDF model        # must be of shape (width, height, numChannels)        # The leading batch size is taken care of by Keras        with IsolatedSession(using_keras=True) as issn:            model = Sequential()            # Make the test model simpler to increase the stability of travis tests            model.add(Flatten(input_shape=(640, 480, 3)))            # model.add(Dense(64, activation='relu'))            model.add(Dense(16, activation='softmax'))            # Initialize the variables            init_op = tf.global_variables_initializer()            issn.run(init_op)            makeGraphUDF(issn.graph,                         'my_keras_model_udf',                         model.outputs,                         {tfx.op_name(model.inputs[0], issn.graph): 'image_col'})            # Run the training procedure            # Export the graph in this IsolatedSession as a GraphFunction            # gfn = issn.asGraphFunction(model.inputs, model.outputs)            fh_name = "test_keras_simple_sequential_model"            registerKerasImageUDF(fh_name, model)        self._assert_function_exists(fh_name) 
开发者ID:databricks,项目名称:spark-deep-learning,代码行数:27,代码来源:keras_sql_udf_test.py


示例17: build_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def build_model(self):        input = Input(shape=self.state_size)        conv = Conv2D(16, (8, 8), strides=(4, 4), activation='relu')(input)        conv = Conv2D(32, (4, 4), strides=(2, 2), activation='relu')(conv)        conv = Flatten()(conv)        fc = Dense(256, activation='relu')(conv)        policy = Dense(self.action_size, activation='softmax')(fc)        value = Dense(1, activation='linear')(fc)        actor = Model(inputs=input, outputs=policy)        critic = Model(inputs=input, outputs=value)        actor.summary()        critic.summary()        return actor, critic 
开发者ID:rlcode,项目名称:reinforcement-learning-kr,代码行数:18,代码来源:play_a3c_model.py


示例18: build_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Flatten [as 别名]def build_model(self):        input = Input(shape=self.state_size)        conv = Conv2D(16, (8, 8), strides=(4, 4), activation='relu')(input)        conv = Conv2D(32, (4, 4), strides=(2, 2), activation='relu')(conv)        conv = Flatten()(conv)        fc = Dense(256, activation='relu')(conv)        policy = Dense(self.action_size, activation='softmax')(fc)        value = Dense(1, activation='linear')(fc)        actor = Model(inputs=input, outputs=policy)        critic = Model(inputs=input, outputs=value)        # 
Python layers.Conv2D方法代码示例
Python layers.Activation方法代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。