当前位置:网站首页>[deep learning] data segmentation
[deep learning] data segmentation
2022-06-30 05:51:00 【Pie Daxing's good friend Dingdang cat】
Before training the model , To split the data set , Divide into training sets according to a certain proportion 、 Test set 、 Verification set , In some cases, test sets can also be ignored , The author has divided the test set here ( Training set : Test set : Verification set =8:1:1), Nonsense , Go straight to the code
# h_split.py
import os
from shutil import copy
import random
def mkfile(file):
if not os.path.exists(file):
os.makedirs(file)
file = 'h_data/h_photos'
h_class = [cla for cla in os.listdir(file) if ".txt" not in cla]
# cla for cla in os.listdir(file) if ".txt" not in cla
# lookup file All the files in the directory , That is to say, the classification is based on file The number of folders under the directory determines the category of classification
# Create training set
mkfile('h_data/train')
for cla in helmet_class:
mkfile('h_data/train/'+cla)
# Create test set
mkfile('h_data/test')
# Create validation set
mkfile('h_data/val')
for cla in helmet_class:
mkfile('h_data/val/'+cla)
split_rate = 0.1
for cla in h_class:
cla_path = file + '/' + cla + '/'
images = os.listdir(cla_path) # images Stored the names of all pictures
num = len(images)
eval_index = random.sample(images, k=int(num*split_rate))
# print(eval_index)
# from images Extract from the list k individual ,num For the total number of pictures ,split_rate For custom scale
# The randomly extracted data is the verification set , eval_index Name the picture
rest_images = list(set(images).difference(set(eval_index)))
# take images and eval_index The difference between the set , Get not in eval_index Picture in
test_index = random.sample(rest_images, k=int(num*split_rate))
# Get the test set data
for index, image in enumerate(images):
# enumerate() Function traverses an object in an indexed sequence
if image in eval_index:
image_path = cla_path + image
new_path = 'h_data/val/' + cla
copy(image_path, new_path)
elif image in test_index:
image_path = cla_path + image
new_path = 'h_data/test/'
copy(image_path, new_path)
else:
image_path = cla_path + image
new_path = 'h_data/train/' + cla
copy(image_path, new_path)
print("\r[{}] processing [{}/{}]".format(cla, index+1, num), end="") # processing bar
print()
print("processing done!")
In particular
1.file: Change to the directory where your data resides
2. The author's directory structure is as follows :
3. Data split file (h_split.py) Same as h_data Put it in the same directory
边栏推荐
- 86. 分隔链表
- D. Big Brush
- [Blue Bridge Road -- bug free code] DS1302 time module code analysis
- uboot通过终端发送‘r‘字符读取ddr内存大小
- UML tools
- Rotating box target detection mmrotate v0.3.1 getting started
- Xi'an Jiaotong 21st autumn economics online homework answer sheet (III) [standard answer]
- 09- [istio] istio service entry
- AI大模型落地大考,浪潮交出了怎样的答卷?
- 14x1.5cm vertical label is a little difficult, VFP calls bartender to print
猜你喜欢

Digital signature——

What indicators should safety service engineers pay attention to in emergency response?

MySQL advanced (Advanced SQL statement)

Redistemplate common method summary

Inno setup the simplest user-defined interface effect

Voting vault: a new primitive for defi and Governance

Leetcode56. consolidation interval

Projet Web de déploiement du serveur Cloud

2022年,谁在推动音视频产业的新拐点?

Switch to software testing and report to the training class for 3 months. It's a high paying job. Is it reliable?
随机推荐
剑指 Offer 18. 删除链表的节点
C. Divan and bitwise operations
unity 扫描圈 圆扩展方法
leetcode763. Divide letter interval
Here comes the nearest chance to Ali
Word frequency statistics (string, list)
86. separate linked list
What are membrane stress and membrane strain
声网,站在物联网的“土壤”里
On line assignment of financial cost management in the 22nd spring of Western Polytechnic University [Full Score answer]
Redistemplate common method summary
[untitled] user defined function
Promise知识点拾遗
Attempt to redefine 'timeout' at line 2 solution
Use the code cloud publicholiday project to determine whether a day is a working day
AI大模型落地大考,浪潮交出了怎样的答卷?
Did you know that WPS can turn on eye protection mode?
At the age of 32, I fell into a middle-aged crisis and finally quit naked...
El table lazy load refresh
Codeforces C. Andrew and Stones