当前位置:网站首页>将一个文件夹图片分成训练集和测试集
将一个文件夹图片分成训练集和测试集
2022-06-12 05:43:00 【LEO-max】
import os
import random
import shutil
from shutil import copy2
rootDir = "./data"
datadir_normal = "./data/JPEGImages/"
all_data = os.listdir(datadir_normal) # (图片文件夹)
num_all_data = len(all_data)
print("num_all_data: " + str(num_all_data))
index_list = list(range(num_all_data))
random.shuffle(index_list)
num = 0
trainDir = rootDir + "/ImageSets/train/normal" # (将训练集放在这个文件夹下)
if not os.path.exists(trainDir):
os.makedirs(trainDir)
testDir = rootDir + "/ImageSets/test/normal" # (将测试集放在这个文件夹下)
if not os.path.exists(testDir):
os.makedirs(testDir)
for i in index_list:
fileName = os.path.join(datadir_normal, all_data[i])
if num < num_all_data * 0.8:
copy2(fileName, trainDir)
else:
copy2(fileName, testDir)
num += 1
print(len(trainDir))
print(len(testDir))
边栏推荐
猜你喜欢

Tabulation skills and matrix processing skills

Project requirements specification

The application could not be installed: INSTALL_FAILED_TEST_ONLY

Heap classical problem

个体工商户是不是法人企业

beginning一款非常优秀的emlog主题v3.1,支持Emlog Pro

Halcon 3D 1 读取3d数据

什么是工程预付款

DMA RDMA technology details

Towards End-to-End Lane Detection: an Instance SegmentationApproach
随机推荐
Select gb28181, RTSP or RTMP for data push?
登录验证过滤器
【js小知识】轻松了解js防抖与节流
Why should state-owned enterprises go public
Go interface oriented programming practice
38. arrangement of strings
Webrtc AEC process analysis
网络加速谁更猛?CDN领域再现新王者
Role and understanding of proc/cmdline
Project requirements specification
How Wireshark decrypts WiFi data packets
Nature | 给全球的新冠伤亡算一笔账
分公司负责人需要承担的法律责任
Deep understanding of asynchronous programming
Introduction to thread pool: ThreadPoolExecutor
Test work summary - performance test related issues
UBI details and JFFS2 square FS UBIFS
March 4, 2021
[Speech] 如何根据不同国家客制化ring back tone
Matlab: image rotation and interpolation and comparison of MSE before and after