【发布时间】:2020-10-22 11:27:48
【问题描述】:
我正在尝试使用 this Plant Leaves dataset(包含 .JPG、.PNG 和 .JPEG 文件的超过 35k 张图像)和 tensorflow 版本 1.14 使用 this tutorial
我遵循了类似的步骤,除了;跳过“使用 keras.preprocessing 加载”部分。我直接跳到“使用 tf.data 加载”部分。但是当我运行 sn-p 时,它向我抛出了这个错误:
File "D:\Softwares\Anaconda\lib\site-packages\tensorflow\python\ops\ragged\ragged_string_ops.py", line 640, in strings_split_v1
return ragged_result.to_sparse()
AttributeError: 'Tensor' object has no attribute 'to_sparse'
dir_root=pathlib.Path("D:/Projects/IIIT/LeafID/Dataset/PlantVillage")
list_ds=tf.data.Dataset.list_files(str(dir_root/"*/*"))
def getLabel(fpath):
parts = tf.strings.split(fpath, os.path.sep)
return parts[-2] == clnames
def decodeimg(img):
img=tf.image.decode_jpeg(img,channels=3)
img=tf.image.convert_image_dtype(img,tf.float32)
return tf.image.resize(img,[64,64])
def process_path(fpath):
label=getLabel(fpath)
img=tf.io.read_file(fpath)
img=decodeimg(img)
return img, label
label_ds=list_ds.map(process_path,num_parallel_calls=AUTOTUNE)
这几乎类似于代码here,除了变量。 我不明白这里有什么问题? 图像转换为张量的过程是否有问题?因为当我打开 ragged_string_ops.py 时,它会显示如下内容:
if result_type == "SparseTensor":
return ragged_result.to_sparse()
T.I.A.
【问题讨论】:
标签: python image tensorflow loaddata