keras txt 读取训练数据_keras 从txt加载预测数据

ImageDataGenerator.flow_from_directory()的用法已经非常多了,优点是简单方便,但数据量很大时,需要组织目录结构和copy数据,很浪费资源和时间

2. 预测时从txt加载数据:

... ...

def get_gen(img_root_txt,_BS):

cnt = 0

imgs = []

files = []

for n in open(img_root_txt):

_n = n[:-1]

files.append(_n)

img_2 = image.load_img(_n, target_size=(64, 64))

img_3 = (image.img_to_array(img_2))/255

img_3 = np.expand_dims(img_3, axis=0)

imgs.append(img_3)

if cnt > _BS:

break

cnt = cnt + 1

x = np.concatenate([x for x in imgs])

print(x.shape)

return x,files

gen,files = get_gen('./imgs_root.txt', BS)

xx = model.predict(gen)

for n,m in zip(files, xx):

if m[0]

print(n, m)

... ...

注意:txt存数据路径,预测结果是各个分类的概率,!!!预测时图像预处理方式与训练时图像预处理方式需保持一致(尺寸、归一化等)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值