码迷,mamicode.com
首页 > 其他好文 > 详细

文件夹自动标号分类

时间:2018-05-30 12:09:52      阅读:362      评论:0      收藏:0      [点我收藏+]

标签:rate   with open   文件   for   \n   pen   form   dir   pre   

def read_img(path):
    imgs = []
    labels = []
    # classs = []
    classs = os.listdir(path)

    for idx, folder in enumerate(classs):
        cate = os.path.join(path, folder)
        for im in os.listdir(cate):
            print(im)
            img_path =os.path.join(cate, im)
            print(reading the images:%s % (img_path))
            img = io.imread(img_path)
            img = transform.resize(img, (w, h))
            # with open(‘tests.txt‘, ‘a‘) as f:
            #     f.write(img_path+‘_‘+str(idx)+‘\n‘)
            imgs.append(img)
            labels.append(idx)
    return np.asarray(imgs, np.float32), np.asarray(labels, np.int32)

 

文件夹自动标号分类

标签:rate   with open   文件   for   \n   pen   form   dir   pre   

原文地址:https://www.cnblogs.com/ansang/p/9110047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!