python - 如何使用 image_dataset_from_directory 为 AutoKeras ImageRegressor 构建 tf.Data.Dataset?
问题描述
如何为 AutoKeras ImageRegressor ( https://autokeras.com/tutorial/image_regression/ ) 构建 tf.Data.Dataset?
我使用的一些步骤来自页面:https ://autokeras.com/tutorial/load/
我可以通过这种方式从单个文件夹中加载图像:
batch_size = 32
img_height = 180
img_width = 180
data_dir = "/data"
x_train = ak.image_dataset_from_directory(
data_dir,
validation_split=0,
subset="training",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
然后我可以使用 numpy 加载相应的响应值(通过一些额外的处理来获得一个 numpy 数组,每个图像都有 1 个值):
y_train = np.genfromtxt("data.txt", delimiter='')
然后我可以使用 take 和 skip 分割生成的数据集,同时获取 numpy 数组的一个子集:
train_size = int(0.8 * n_rows)
val_size = int(0.2 * n_rows)
x_train_sm = x_train.take(train_size)
x_val_sm = x_train.skip(train_size)
y_train_sm = y_train[0:train_size]
y_val_sm = y_train[train_size:]
但是运行回归拟合给了我这个问题:
reg = ak.ImageRegressor(max_trials=max_trials, metrics=['mean_squared_error'], overwrite=False)
reg.fit(x_train_sm, y_train_sm, validation_split=0.2, batch_size=batch_size)
带有错误消息:
ValueError: Expected y to be None when x is tf.data.Dataset.
解决方案
推荐阅读
- listview - 从 ListView KOTLIN 中选择项目后的多个操作
- angular - 使用外部 js 库构建 Angular 5 包
- html - ol 项目符号类型和文本 css
- javascript - 非 UTC 和 UTC 日期比较结果不同
- google-apps-script - 公共 Google 脚本不能从 chrome 扩展程序运行
- webview - RPi3 上的 WebRTC 在使用 WebView 的 getUserMedia() 上失败
- sql - 如何排除“?” 对于来自 DB2 Select 的 Null 值
- php - sudo 没有访问权限,即使它是用 sudo visudo 添加的
- vba - VBA - 通过 DblClick 事件关闭打开的表单,关闭整个运行代码?
- java - 执行多个 Cucumber 测试的模式是什么