使用tf.data.Dataset作为预处理的一部分运行另一个模型(自动编码器)

时间:2018-11-13 14:51:34

标签: tensorflow keras tensorflow-datasets

我正在尝试训练一个分类器,作为分类器预处理管道的一部分,我想运行另一个模型,即自动编码器。

我正在使用tf.data.Dataset预处理我的数据并计算分类器的输入。我的脚本就是这个

def patch_fn(image, label):
  x = keras.layers.Input(shape=(1,))
  y = keras.layers.Dense(10)(x)
  model = keras.models.Model(x, y)  # This is the autoencoder
  encoded_y = model.predict(image, steps=1)
  return encoded_y, label

def input_fn():
  dataset = tf.data.TFRecordDataset(...)
  dataset = dataset.map(patch_fn)
  dataset = ...

def main():
  classifier = ...
  classifier.fit(input_fn(...), ...)

但是当我运行它时,我得到了

tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'dense/MatMul/ReadVariableOp/Placeholder' with dtype resource
     [[{{node dense/MatMul/ReadVariableOp/Placeholder}} = Placeholder[dtype=DT_RESOURCE, shape=[], _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]
     [[{{node dense/BiasAdd/_3}} = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_13_dense/BiasAdd", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

有人愿意指出正确的方向吗?谢谢。

0 个答案:

没有答案