AttributeError:“模型”对象没有属性“ _name”

时间:2018-12-09 19:56:50

标签: python tensorflow keras

$('#add').click(function (event) {
    console.log('add');
    event.preventDefault();

    $('#tasklist').on('change', '.itemdone', itemdone);
    $('#tasklist').on('click', '.deleteItem', deleteItem);

    $('#addtolist').on('keypress', function (event) {
      if (event.which === 13) {
        addItem();
        event.preventDefault();
      }
    });

    var taskitem = $('#addtolist').val();
    if (taskitem.length > 0) {
      $('#tasklist').append('<li><input class = "itemdone" type="checkbox">' + taskitem +
      '<span class="glyphicon glyphicon-trash deleteItem"></span></li>');
      $('#addtolist').val('');
    }

    function deleteItem() {
      $(this).parent().remove();
    }

    function itemdone() {
      $(this).parent().toggleClass('done');
    }

运行此代码后,出现此错误。 我要做的是从自动编码器中提取解码器。

我看到了here,他们在那里提取了层的索引。但是我不知道索引。

from tensorflow.keras.layers import Input, Dense
from tensorflow.keras.models import Model


input_img = Input(shape=(784,))
encoded = Dense(128, activation='relu')(input_img)
encoded = Dense(64, activation='relu')(encoded)
encoded = Dense(64, activation='relu')(encoded)
encoded = Dense(64, activation='relu')(encoded)
encoded = Dense(64, activation='relu')(encoded)
encoded = Dense(64, activation='relu')(encoded)
encoded = Dense(32, activation='relu', name='encoder_output')(encoded)
decoded = Dense(64, activation='relu', name='decoder_input')(encoded)
decoded = Dense(128, activation='relu')(decoded)
decoded = Dense(128, activation='relu')(decoded)
decoded = Dense(128, activation='relu')(decoded)
decoded = Dense(128, activation='relu')(decoded)
decoded = Dense(128, activation='relu')(decoded)
decoded = Dense(784, activation='sigmoid')(decoded)
autoencoder = Model(input_img, decoded)

decoder = Model(inputs=autoencoder.get_layer('decoder_input').input,outputs=autoencoder.output)

1 个答案:

答案 0 :(得分:1)

我不确定这些示例来自哪里,但是解剖API来创建这些模型并不是预期的用法。如果您看一下库作者的blog post,则最好将编码器和解码器这样分开:

[Apple, Apple]

关键是input_img = Input(shape=(784,)) encoded = Dense(128, activation='relu')(input_img) encoded = Dense(64, activation='relu')(encoded) encoded = Dense(64, activation='relu')(encoded) encoded = Dense(64, activation='relu')(encoded) encoded = Dense(64, activation='relu')(encoded) encoded = Dense(64, activation='relu')(encoded) encoded = Dense(32, activation='relu')(encoded) encoder = Model(input_img, encoded) decoder_input = Input(shape=(32,)) decoded = Dense(64, activation='relu')(decoder_input) decoded = Dense(128, activation='relu')(decoded) decoded = Dense(128, activation='relu')(decoded) decoded = Dense(128, activation='relu')(decoded) decoded = Dense(128, activation='relu')(decoded) decoded = Dense(128, activation='relu')(decoded) decoded = Dense(784, activation='sigmoid')(decoded) decoder = Model(decoder_input, decoded) autoenc = decoder(encoder(input_img)) autoencoder = Model(input_img, autoenc) 只是另一层,实际上它继承自Model类。因此,您可以创建较小的模型,然后像图层一样使用它们。