Ejemplo n.º 1
0
    def __init__(self):
        super(Generator, self).__init__()
        # z:[b, 100]->[b, 3*3*512]->[b, 3, 3, 512]->[b,64,64,3]

        self.fc = layers.Dense(3 * 3 * 512)  #[b,100]->[b,3*3*512]

        self.conv1 = layers.Conv2DTranspose(256, 3, 3, 'valid')
        self.bn1 = layers.BatchNormalization()

        self.conv2 = layers.Conv2DTranspose(128, 5, 2, 'valid')
        self.bn2 = layers.BatchNormalization()

        self.conv3 = layers.Conv2DTranspose(3, 4, 3, 'valid')
def tf_model_full():
    model = keras.Sequential([
        layers.BatchNormalization(input_shape=[
            40,
        ]),
        layers.Dense(4, activation='relu'),
        layers.BatchNormalization(),
        layers.Dense(8, activation='relu'),
        layers.Dense(1, activation='sigmoid')
    ])
    model.compile(optimizer=tf.optimizers.SGD(lr=0.001,
                                              decay=1e-5,
                                              nesterov=True,
                                              momentum=0.9),
                  loss='binary_crossentropy',
                  batch_size=256,
                  metrics=['accuracy'])
    return model
Ejemplo n.º 3
0
 def __init__(self,_lambda,layer_dims,num_classes=10,kind='res'):
     super(ResNet,self).__init__()
     self.stem=Sequential([layers.Conv2D(64,(3,3),strides=(1,1)),layers.BatchNormalization(),layers.ReLU(),layers.MaxPool2D(pool_size=(2,2),strides=(1,1),padding='same')])
     self.layer1=self.bulid_block(64,layer_dims[0],kind=kind)
     self.layer2=self.bulid_block(128,layer_dims[1],stride=2,kind=kind)
     self.layer3=self.bulid_block(256,layer_dims[2],stride=2,kind=kind)
     self.layer4=self.bulid_block(512,layer_dims[3],stride=2,kind=kind)
     self.avg_pool=layers.GlobalAveragePooling2D()
     self.fcm=layers.Dense(1000,activation='relu',kernel_regularizer=regularizers.l2(_lambda))
     self.fc=layers.Dense(num_classes)
Ejemplo n.º 4
0
 def __init__(self,filter_num,stride=1,kind='res'):
     super(BasicBlock,self).__init__()
     self.kind=kind
     if kind=='res':
         self.conv1=layers.Conv2D(filter_num,(3,3),strides=stride,padding='same')
         self.bn1=layers.BatchNormalization()
         self.relu=layers.ReLU()
         self.conv2=layers.Conv2D(filter_num,(3,3),strides=1,padding='same')
         self.bn2=layers.BatchNormalization()
         if stride!=1:
             self.downsample=Sequential()
             self.downsample.add(layers.Conv2D(filter_num,(1,1),strides=stride))
         else:
             self.downsample= lambda x:x
     elif kind=='Dense':
         self.conv1=layers.Conv2D(filter_num,(3,3),strides=stride,padding='same')
         self.bn1=layers.BatchNormalization()
         self.relu=layers.ReLU()
         self.conv2=layers.Conv2D(filter_num,(3,3),strides=1,padding='same')
         self.bn2=layers.BatchNormalization()
         self.conv3=layers.Conv2D(filter_num,(3,3),strides=1,padding='same')
         self.bn3=layers.BatchNormalization()
         self.conv4=layers.Conv2D(filter_num,(3,3),strides=1,padding='same')
         self.bn4=layers.BatchNormalization()
         if stride!=1:
             self.downsample13=Sequential()
             self.downsample13.add(layers.Conv2D(filter_num,(1,1),strides=stride))
             self.downsample14=Sequential()
             self.downsample14.add(layers.Conv2D(filter_num,(1,1),strides=stride))
             self.downsample15=Sequential()
             self.downsample15.add(layers.Conv2D(filter_num,(1,1),strides=stride))
             self.downsample=lambda x:x
         else:
             self.downsample= lambda x:x
def getModel():
    model = keras.Sequential([
        layers.Input(shape=[4,]),
        layers.BatchNormalization(),
        layers.Dense(16,activation='relu'),
        layers.BatchNormalization(),
        layers.Dense(32,activation='relu'),
        layers.Dense(1,activation='sigmoid')
    ])
    # lr=0.001, decay=1e-5, nesterov=True, momentum=0.9
    model.compile(optimizer=tf.optimizers.SGD(lr=0.001, decay=1e-5, nesterov=True, momentum=0.9),
              loss='binary_crossentropy',
              batch_size=32,
              metrics=['accuracy']
              )
    '''
    model.compile(optimizer="rmsprop",
              loss='binary_crossentropy',
              metrics=['accuracy'],
              )
    '''
    return model
Ejemplo n.º 6
0
    def __init__(self):
        super(Discriminator, self).__init__()
        # [b,64,64,3]->[b, 20,20,64]
        # Conv2D(filters, kernel_size, strides, padding)
        # filters  输出的空间维度,即卷积中的滤波器数
        # kernel_size  卷积核的大小。2个整数的整数元组/列表,指定2D卷积窗口的高度和宽度.可以是单个整数,以指定所有空间维度的相同值。
        # 这里的5就是5*5
        # strides 2个整数的整数或元组/列表,指定卷积沿高度和宽度的跨度.可以是单个整数,以指定所有空间维度的相同值.指定任何步幅值!= 1与指定任何dilation_rate值!= 1都不相容
        self.con1 = layers.Conv2D(64, 5, 3, 'valid')

        # [b,20,20,3]->[b, 20,20,128]
        self.con2 = layers.Conv2D(128, 5, 3, 'valid')
        self.bn2 = layers.BatchNormalization()

        # [b,20,20,128]->[b, 20,20,256]
        self.con3 = layers.Conv2D(256, 5, 3, 'valid')
        self.bn3 = layers.BatchNormalization()

        # 打平 [b, h, w, c]->[b, -1] 就保留第0维度,其余的维度相乘,如[b, 2, 2, 3]->[b, 2*2*3]
        self.flatten = layers.Flatten()

        # 全连接层[b, -1]->[b, 1]
        self.fc = layers.Dense(1)