Keras / Tensorflow:“您必须使用dtype float和shape [?,600,451,3]为占位符张量'input_1'提供值”

问题描述 投票:1回答:2

我有这个CNN,我正在努力。输入形状是动态的,但我将其固定为[?,600,451,3](batch_size,height,width,channels),以便我可以调试它。

我有一个我创建的随机批处理生成器:

test = random_batch_generator(z_train
                    , num_processes=12 
                    , num_batch=steps_train 
                    , preloaded_batch=100
                    , batch_size=batch_size
                    , chunk_size=batch_size
                    , dataaugmfunc=heavy_dataaugm
                    , seq=seq
                    , initial_dim=initial_dim
                    , min_overlap=MINOVERLAP
                    )

当我做:

next(test)[0].shape

要么

next(test)[0].dtype

它输出正确的形状([?,600,451,3])和dtype(float32),理论上我需要输入。我也检查了批次的内容,看起来不错。

不过,当我用以下方法训练我的模型时,我得到了:

model.fit_generator(
        random_batch_generator(z_train (...)),
        validation_data= (x_val_mem,y_val_mem),
        steps_per_epoch=steps_train,
        validation_steps=steps_val,
        epochs=epochs
        ,callbacks=model_callbacks(modelname)
        ,class_weight = [0.005,0.995]
    )

此错误消息:

InvalidArgumentError(请参见上面的回溯):您必须为占位符张量'input_1'提供一个值,其中dtype为float和shape [?,600,451,3]

[[Node:input_1 = Placeholderdtype = DT_FLOAT,shape = [?,600,451,3],_ device =“/ job:localhost / replica:0 / task:0 / device:GPU:0”]]

我究竟做错了什么?万分感谢您对此的任何帮助或直觉。

tensorflow keras
2个回答
1
投票

你在使用TensorBoard回调吗?如果是这样,您可以在创建模型之前尝试添加它

import keras.backend as K
K.clear_session()

here


0
投票

不确定这是原因,但某些内容与验证数据不兼容。

如果您将验证数据作为数组,则将其作为validation_data=(array_x, array_y)传递,并且没有validation_steps

现在,如果它是一个生成器,那么你需要将它作为validation_data = someGenerator传递,然后你传递validation_steps=number_of_batches_expected_from_generator

© www.soinside.com 2019 - 2024. All rights reserved.