繁体   English   中英

当我生成噪声张量时,出现以下错误:AttributeError:'Tensor'对象没有属性'_keras_history'

[英]When I generate a noise tensor I get this error: AttributeError: 'Tensor' object has no attribute '_keras_history'

这行:

z = random_normal(shape = (-1, 8, 8, 256), 
                     mean = 0.0, stddev = 1.0, dtype = None, seed = None)

给出错误:

AttributeError: 'Tensor' object has no attribute '_keras_history'.

有谁知道我该如何解决?

但是我实际上设法避免了这个问题。 我给z就像函数的输入一样。 我使用输入层创建它。

image = Input(shape = (128, 128, 3))
noise = random_normal(shape = (-1, 8, 8, 100), mean = 0.0, stddev = 1.0, dtype = None, seed = None)
noise = Input(tensor =  noise)

gen_out   = generator_network(image, noise)
gen_model = Model(inputs = [image, noise], outputs = gen_out)

def generator_network(input_tensor, noise):
    """
    The generator network, G has two pathways, with one global network Gg processing
    the global structure of the face and a local one for the main face features: eyes,
    mouth, nose. Each path has an encoder - decoder structure with skip connections.
    :INPUT : Input tensor corresponding to an image, a face profile.
    :OUTPUT: Output tensor that corresponds to the frontal face.
    """
    # Global pathway encoder
    conv0 = Conv2D(filters = 64, kernel_size = (7, 7), padding = 'same', strides = (1, 1))(input_tensor)
    conv0 = BatchNormalization()(conv0)
    conv0 = LeakyReLU(0.2)(conv0)
    conv0 = resnet_block(conv0, 64)

    conv1 = Conv2D(filters = 64, kernel_size = (5, 5), padding = 'same', strides = (2, 2))(conv0)
    conv1 = BatchNormalization()(conv1)
    conv1 = LeakyReLU(0.2)(conv1)
    conv1 = resnet_block(conv1, 64)

    conv2 = Conv2D(filters = 128, kernel_size = (3, 3), padding = 'same', strides = (2, 2))(conv1)
    conv2 = BatchNormalization()(conv2)
    conv2 = LeakyReLU(0.2)(conv2)
    conv2 = resnet_block(conv2, 128)

    conv3 = Conv2D(filters = 256, kernel_size = (3, 3), padding = 'same', strides = (2, 2))(conv2)
    conv3 = BatchNormalization()(conv3)
    conv3 = LeakyReLU(0.2)(conv3)
    conv3 = resnet_block(conv3, 256)

    conv4 = Conv2D(filters = 512, kernel_size = (3, 3), padding = 'same', strides = (2, 2))(conv3)
    conv4 = BatchNormalization()(conv4)
    conv4 = LeakyReLU(0.2)(conv4)
    for i in range(4):
        conv4 = resnet_block(conv4, 512)

    fc1 = Dense(512)(conv4)
    f1  = Lambda(lambda x: x[:, : , :,   0:256])(fc1)
    f2  = Lambda(lambda x: x[:, : , :, 256:512])(fc1)
    fc2 = maximum([f1, f2])

    # Concatenation with noise vector
    v = concatenate([fc2, noise])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM