我有 10000 张一些手写数字的 BMP 图片。如果我想将数据提供给神经网络,我需要做什么?对于 MNIST 数据集,我只需要写
(X_train, y_train), (X_test, y_test) = mnist.load_data()
我在 python 中使用 Keras 库。我怎样才能创建这样的数据集?
原文由 Md Shopon 发布,翻译遵循 CC BY-SA 4.0 许可协议
我有 10000 张一些手写数字的 BMP 图片。如果我想将数据提供给神经网络,我需要做什么?对于 MNIST 数据集,我只需要写
(X_train, y_train), (X_test, y_test) = mnist.load_data()
我在 python 中使用 Keras 库。我怎样才能创建这样的数据集?
原文由 Md Shopon 发布,翻译遵循 CC BY-SA 4.0 许可协议
您应该编写自己的函数来加载所有图像或这样做:
imagePaths = sorted(list(paths.list_images(args["testset"])))
# loop over the input images
for imagePath in imagePaths:
# load the image, pre-process it, and store it in the data list
image = cv2.imread(imagePath)
image = cv2.resize(image, (IMAGE_DIMS[1], IMAGE_DIMS[0]))
image = img_to_array(image)
data.append(image)
# extract the class label from the image path and update the
# labels list
data = np.array(data, dtype="float") / 255.0
原文由 azharimran 发布,翻译遵循 CC BY-SA 4.0 许可协议
2 回答5.2k 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
4 回答1.4k 阅读✓ 已解决
3 回答1.3k 阅读✓ 已解决
3 回答1.3k 阅读✓ 已解决
2 回答862 阅读✓ 已解决
1 回答1.7k 阅读✓ 已解决
您可以编写一个函数来加载所有图像并将它们堆叠到一个 numpy 数组中(如果所有图像都适合 RAM),或者使用包含一个函数的 Keras ImageDataGenerator( https://keras.io/preprocessing/image/ )
flow_from_directory
。您可以在此处找到示例 https://gist.github.com/fchollet/0830affa1f7f19fd47b06d4cf89ed44d 。