【发布时间】:2021-12-27 19:35:47
【问题描述】:
我正在尝试加载一个数据集,该数据集存储在我的驱动器上的两个 .npy 文件(用于特征和基本事实)中,并使用它来训练神经网络。
print("loading features...")
data = np.load("[...]/features.npy")
print("loading labels...")
labels = np.load("[...]/groundtruth.npy") / 255
dataset = tf.data.Dataset.from_tensor_slices((data, labels))
调用from_tensor_slices() 方法时抛出tensorflow.python.framework.errors_impl.InternalError: Failed copying input tensor from /job:localhost/replica:0/task:0/device:CPU:0 to /job:localhost/replica:0/task:0/device:GPU:0 in order to run _EagerConst: Dst tensor is not initialized. 错误。
ground truth 的文件大于 2.44GB,因此我在使用它创建数据集时遇到问题(请参阅警告 here 和 here)。
我发现的可能解决方案是 TensorFlow 1.x(here 和 here,而我正在运行 2.6 版)或使用 numpy 的 memmap (here),很遗憾我没有得到运行,另外我想知道这是否会减慢计算速度?
感谢您的帮助,谢谢!
【问题讨论】:
-
我最终将我的数据集分成两部分并以这种方式阅读,但您的建议帮助我理解了潜在问题并跳出框框思考。我会把它标记为答案,再次感谢你:)
标签: python numpy tensorflow dataset tensorflow-datasets