2017-10-12 73 views
0

这行:当我产生噪音张我得到这个错误:AttributeError的:“张量”对象有没有属性“_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'. 

有任何人任何我怎么能解决它?

+0

的可能的复制[AttributeError的: '张量' 对象没有属性 '\ _keras \ _history'](https://stackoverflow.com/questions/44889187/attributeerror-tensor-object-has-no-attribute -keras-history) –

+2

请包含产生此错误的完整示例。 –

回答

0

但我真的设法避免了这个问题。我给了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]) 
相关问题