没有合适的资源?快使用搜索试试~ 我知道了~
python脚本生成caffe train_list.txt的方法
1 下载量 31 浏览量
2020-12-25
06:38:18
上传
评论
收藏 79KB PDF 举报
温馨提示
试读
4页
首先给出代码: import os path = "/home/data//" path_exp = os.path.expanduser(path) classes = [int(p) for p in os.listdir(path_exp)] classes.sort() # nrof_classes一个数据集下有多少个文件夹,就是说有多少个人,多少个类别 nrof_classes = len(classes) count=0 files = open("train_list.txt",'w') filets = open("test_list.txt",'w') count_u=0
资源详情
资源评论
资源推荐
python脚本生成脚本生成caffe train_list.txt的方法的方法
首先给出代码:首先给出代码:
import os
path = "/home/data//"
path_exp = os.path.expanduser(path)
classes = [int(p) for p in os.listdir(path_exp)] classes.sort()
# nrof_classes一个数据集下有多少个文件夹,就是说有多少个人,多少个类别
nrof_classes = len(classes)
count=0
files = open("train_list.txt",'w')
filets = open("test_list.txt",'w')
count_u=0
for i in range(nrof_classes):
class_name = str(classes[i])
count=count+1
count_u=count_u+1
facedir = os.path.join(path_exp, class_name)
prefix1 = path+class_name+"/"
if os.path.isdir(facedir):
images = os.listdir(facedir)
#print(images[0])
image_paths = [(prefix1+img+" "+class_name+"") for img in images] #print(image_paths[0])
if count < 0.8*nrof_classes:
if len(image_paths)>4:
test_path=[] for x in range(2):
test_path.append(image_paths[0])
del image_paths[0] filets.writelines(test_path)
files.writelines(image_paths)
#if count==2:
# break
#imgae_pathses = [] #防止图像大小为0
#for x in image_paths:
# if os.path.getsize(x)>0:
# imgae_pathses.append(x)
#if len(imgae_pathses)==0:
# os.rmdir(facedir)
files.close()
filets.close()
python下下os模块的一下有用的用法:模块的一下有用的用法:
0 重命名:文件和文件夹都是一个命令:
os.rename(original_dir,new_dir)
1 文件操作:文件操作:
os.mknod(“test.txt”) 创建空文件
fp = open(“test.txt”,w) 直接打开一个文件,如果文件不存在则创建文件
关于open 模式:
w 以写方式打开,
a 以追加模式打开 (从 EOF 开始, 必要时创建新文件)
r+ 以读写模式打开
w+ 以读写模式打开 (参见 w )
a+ 以读写模式打开 (参见 a )
rb 以二进制读模式打开
wb 以二进制写模式打开 (参见 w )
ab 以二进制追加模式打开 (参见 a )
rb+ 以二进制读写模式打开 (参见 r+ )
wb+ 以二进制读写模式打开 (参见 w+ )
ab+ 以二进制读写模式打开 (参见 a+ )
weixin_38717143
- 粉丝: 3
- 资源: 946
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0