【训练过程】1) Create Training File(创建训练文件)
2023-09-14 09:14:43 时间
1) Create Training File(创建训练文件)
Put the folders of VOC dataset(clean images是原始的干净图像(VOC)), collected old photos (e.g., Real_L_old and Real_RGB_old(real_l_old是只有灰度(亮度)的照片集,real_rgb_old是彩色照片集)) into one shared folder. Then
cd Global/data/
python Create_Bigfile.py
Note: Remember to modify the code based on your own environment.
过程:
- 创建3个文件,分别命名为:VOC.bigfile、Real_L_old.bigfile、Real_RGB_old.bigfile,即其中每一个文件夹对应一个大文件
- 向大文件中分别写入总图像数 + 文件名 + 图像数据,即大文件由这三部分组成,
# 1) Create Training File(创建训练文件)
import os
import struct
IMG_EXTENSIONS = ['.jpg', '.JPG', '.jpeg', '.JPEG', '.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP',]
def is_image_file(filename):
"""判断图像是否是文件"""
return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)
def make_dataset(dir):
"""将当前文件夹下的完整图像路径合成为一个list"""
images = []
assert os.path.isdir(dir), '%s is not a valid directory' % dir
for root, _, fnames in sorted(os.walk(dir)):
for fname in fnames:
if is_image_file(fname):
path = os.path.join(root, fname)
images.append(path)
return images
### Modify these lines in your own environment
indir="/data/temp_old"
target_folders=['VOC','Real_L_old','Real_RGB_old']
out_dir ="/data/out_temp_old"
indir = os.path.abspath(os.path.join(os.getcwd(), "../..")+indir)
out_dir = os.path.abspath(os.path.join(os.getcwd(), "../..")+out_dir)
if os.path.exists(out_dir) is False:
os.makedirs(out_dir)
###
# 初始化总共的需要处理的图像的数量
total_num_image = 0
for target_folder in target_folders:
# data/temp_old/VOC、Real_L_old、Real_RGB_old
curr_indir = os.path.join(indir, target_folder)
# 1.创建大文件,data/temp_old/VOC.bigfile、Real_L_old.bigfile、Real_RGB_old.bigfile
curr_out_file = os.path.join(os.path.join(out_dir, '%s.bigfile'%(target_folder)))
# data/temp_old/VOC、Real_L_old、Real_RGB_old三个文件夹下每一个文件夹下的所有的图像文件组成一个列表,总共组成3个列表
image_lists = make_dataset(curr_indir)
image_lists.sort()
with open(curr_out_file, 'wb') as wfid:
# 2.write total image number 写入总图像数
wfid.write(struct.pack('i', len(image_lists)))
for i, img_path in enumerate(image_lists):
# 3.write file name first 先写文件名
img_name = os.path.basename(img_path)
img_name_bytes = img_name.encode('utf-8')
wfid.write(struct.pack('i', len(img_name_bytes)))
wfid.write(img_name_bytes)
# 4.write image data in 写入图像数据
with open(img_path, 'rb') as img_fid:
img_bytes = img_fid.read()
wfid.write(struct.pack('i', len(img_bytes)))
wfid.write(img_bytes)
total_num_image=total_num_image+1
print('write %s images done' % image_lists[i])
print("The total number of images processed is:",total_num_image)
相关文章
- Spring MVC程序中得到静态资源文件css,js,图片
- 转:linux 文件解压命令
- hosts文件位置
- 重新整理 .net core 实践篇—————配置系统之间谍[八](文件监控)
- 【CTF杂项】常见文件文件头文件尾格式总结及各类文件头
- Windows Server 2008 显示隐藏文件 扩展名
- DL:关于深度学习常用数据集中训练好的权重文件(Deeplab v3、MobileNet、InceptionV3、VGG系列、ResNet、Mask R-CNN )下载地址集合(持续更新)
- TF之TFOD-API:基于tensorflow框架利用TFOD-API脚本文件将YoloV3训练好的.ckpt模型文件转换为推理时采用的.pb文件
- TF:利用TF的train.Saver将训练好的W、b模型文件保存+新建载入刚训练好模型(用于以后预测新的数据)
- pytorch保存和加载文件的方法,从断点处继续训练
- leaflet使用L.geoJSON加载文件,参数filter的使用方法(127)
- MATLAB中文件的读写和数据的导入导出
- 基于深度学习的病毒检测技术无需沙箱环境,直接将样本文件转换为二维图片,进而应用改造后的卷积神经网络 Inception V4 进行训练和检测
- 利用HOG+SVM训练自己的XML文件
- labelme的安装以及如何用labelme标注的json文件转换成coco和pascal voc数据集的格式进行深度学习的训练