Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow-ValueError:从拆分数组创建数据集时,无法将NumPy数组转换为张量_Tensorflow_Keras_Tensorflow Datasets - Fatal编程技术网

Tensorflow-ValueError:从拆分数组创建数据集时,无法将NumPy数组转换为张量

Tensorflow-ValueError:从拆分数组创建数据集时,无法将NumPy数组转换为张量,tensorflow,keras,tensorflow-datasets,Tensorflow,Keras,Tensorflow Datasets,所以当我从张量切片创建tf.data.Dataset时,我有一个奇怪的错误,就像这样 train = AB.copy() test = train.sample(2000) train = train[~(train.A.isin(test.A))] x_train = train.A_image.to_numpy() y_train = train.Label.to_numpy() x_test = test.A_image.to_numpy() y_test = test.Label.to_

所以当我从张量切片创建tf.data.Dataset时,我有一个奇怪的错误,就像这样

train = AB.copy()
test = train.sample(2000)
train = train[~(train.A.isin(test.A))]
x_train = train.A_image.to_numpy()
y_train = train.Label.to_numpy()
x_test = test.A_image.to_numpy()
y_test = test.Label.to_numpy()
dataset = tf.data.Dataset.from_tensor_slices(({'image_input': x_train, 'label_input': y_train}, y_train))
ds_test = tf.data.Dataset.from_tensor_slices(({'image_input': x_test, 'label_input': y_test}, y_test))
现在,
dataset
的创建工作正常了 但是
ds_test
会在标题中抛出此错误。 我检查过它们是有效的数组,形状相同。 有时,当我重新启动运行时,同样的代码也会起作用

这里可能有什么问题

谢谢你看


编辑:首先将x_测试转换为列表,然后再转换为数组。可能x_测试恰好是一个空数组?不,不是,它有数千个示例,就像我在编辑中添加的x_列一样,当我对x_列表进行编辑时,然后将np.array(x_测试)包装起来。它可以工作。如果你能用一些虚拟数据显示一些可复制的内容,那会更好。我明白了,我会试着想出一些“恐怖”的东西