python - 使用包含图像的 3 个文件夹创建用于训练和测试的数据
问题描述
我在跑步:
path = Path('/content/drive/MyDrive/X-Ray_Image_DataSet')
np.random.seed(41)
data = ImageDataBunch.from_folder(dta, train="Train", valid ="Valid", ds_tfms=get_transforms(),size=(256,256), bs=32, num_workers=4).normalize()
我收到了这个错误:
/usr/local/lib/python3.7/dist-packages/fastai/data_block.py:458: UserWarning: Your training set is empty. If this is by design, pass `ignore_empty=True` to remove this warning.
warn("Your training set is empty. If this is by design, pass `ignore_empty=True` to remove this warning.")
/usr/local/lib/python3.7/dist-packages/fastai/data_block.py:461: UserWarning: Your validation set is empty. If this is by design, use `split_none()`
or pass `ignore_empty=True` when labelling to remove this warning.
or pass `ignore_empty=True` when labelling to remove this warning.""")
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/fastai/data_block.py in get_label_cls(self, labels, label_cls, label_delim, **kwargs)
264 if label_delim is not None: return MultiCategoryList
--> 265 try: it = index_row(labels,0)
266 except: raise Exception("""Can't infer the type of your targets.
7 frames
IndexError: index 0 is out of bounds for axis 0 with size 0
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/fastai/data_block.py in get_label_cls(self, labels, label_cls, label_delim, **kwargs)
265 try: it = index_row(labels,0)
266 except: raise Exception("""Can't infer the type of your targets.
--> 267 It's either because your data source is empty or because your labelling function raised an error.""")
268 if isinstance(it, (float, np.float32)): return FloatList
269 if isinstance(try_int(it), (str, Integral)): return CategoryList
Exception: Can't infer the type of your targets.
It's either because your data source is empty or because your labelling function raised an error.
解决方案
np.random.seed(41)
data = ImageDataBunch.from_folder(path, train = '.', valid_pct=0.2,
ds_tfms=get_transforms(), size=(256,256), bs=32, num_workers=4).normalize()
你可以用这个代替那个
推荐阅读
- python - Python datetime:tz inside 方法和 .replace(tzinfo=) 之间的区别
- struct - 如何在链表中传递结构?
- python-3.x - 用于大数据集查询的 Gremlin 分页
- java - 在 lint-results-release-fatal 中生成没有任何内容的签名 apk 时出错
- mysql - 意外的 MySql PoolExhaustedException
- javascript - 从纹理图集渲染时,我的纹理相互渗透
- java - 如何通过 json 将本地图像(可绘制图像文件)显示到 cardview。我想离线加载图像而不是使用毕加索库
- c# - Shared method to return string only if needed
- python - gTTS 无法保存文件两次
- postgresql - PostgreSQL:从代码执行查询时“pq:关系列不存在”,但在控制台中工作正常