keras 将A模型某一层初始化为B模型的weights


def A(scope='generator'):
    noise_imgs = Input(shape=inputs_shape)
    features = Input(shape=(4,4,512))
    
    x = Conv2D(filters=512, kernel_size=(3,3), strides=(1,1), padding='same', name='g-con1_1')(noise_imgs)

 

def B(scope='vgg_16_mini'):
    real_imgs = Input(shape=inputs_shape)
    
    x = Conv2D(filters=512, kernel_size=(3,3), strides=(1,1), padding='same', name='d-con1_1')(real_imgs)

使用以下方法初始化:

A.get_layer('g-con1_2').set_weights(B.get_layer('d-con1_2').get_weights())

 

你可能感兴趣的:(AI学习)