【发布时间】:2021-04-03 16:28:25
【问题描述】:
我在 Google Colab 上使用此数据 http://weegee.vision.ucmerced.edu/datasets/landuse.html。
尝试使用以下方法将图像加载为数据框:
# Download and unzip images
!wget http://weegee.vision.ucmerced.edu/datasets/UCMerced_LandUse.zip
!unzip UCMerced_LandUse.zip
print("DONE!")
filename = '//content/UCMerced_LandUse/Images'
data = tf.keras.preprocessing.image_dataset_from_directory(filename)
我收到以下错误:
TypeError: Input 'filename' of 'ReadFile' Op has type float32 that does not match expected type of string.
它找到了带有标签的文件夹,但它错过了每个标签文件夹中的所有 100 张图像。图片格式为“.tif”。
在图片中可以观察到目录结构。
功能:
tf.keras.preprocessing.image.load_img('/content/UCMerced_LandUse/Images/agricultural/agricultural00.tif', grayscale=False, color_mode="rgb", target_size=None, interpolation="nearest")
Works well and show the image.
我已经尝试了以下帖子中的所有内容: TypeError: Input 'filename' of 'ReadFile' Op has type float32 that does not match expected type of string 比如重命名文件:
all_dir = glob.glob('UCMerced_LandUse/Images/*/')
for dir in sort(all_dir):
name = dir.split('/')[2]
for img, n in zip(sort(glob.glob(dir + '*.tif')), range(0,100)):
new_file = os.path.join(dir, '{}{}.tif'.format(name, n))
os.rename(img, str(new_file))
以及互联网上提出的其他一些“解决方案”。但是没有人解决这个问题。
如果你能从我失败的地方找到一些线索,我们将不胜感激。
谢谢。
【问题讨论】:
标签: python tensorflow keras image-preprocessing