当前位置:网站首页>K-fold cross validation
K-fold cross validation
2022-06-25 20:05:00 【Orange cedar】
import os
import cv2
import random
import shutil
import numpy as np
def get_data_crop(k):
# Get all patient sequence names and all training file names
name_list, file_list = [], []
for root, dirs, files in os.walk('./img'):
for f in files:
if f.split('-')[-2] not in name_list:
name_list.append(f.split('-')[-2])
# print(name_list)
file_list.append(root + '/' + f)
random.shuffle(name_list)
#k Crossover verification
for i in range(0,2):
print('name_list:',len(name_list))
fold_size = len(name_list) // k
test_name = name_list[i*fold_size:(i+1)*fold_size]
train_file, test_file = [], []
print('len(test_name):',len(test_name))
print(test_name)
for file in file_list:
print(file.split('/')[-1].split('-')[-2])
if file.split('/')[-1].split('-')[-2] in test_name:
try:
shutil.copy(file,'.\\C\\K10\\test_'+str(i+1)+'\\M\\'+file.split('/')[-1])
shutil.copy(file.replace('img','compound'), '.\\C\\K10\\test_' + str(i+1) + '\\I\\' + file.split('/')[-1])
except Exception:
os.makedirs('.\\C\\K10\\test_'+str(i+1)+'\\M\\')
shutil.copy(file, '.\\C\\K10\\test_'+str(i+1) +'\\M\\' +file.split('/')[-1])
os.makedirs('.\\C\\K10\\test_'+ str(i+1) + '\\I\\')
shutil.copy(file.replace('img', 'compound'),'.\\C\\K10\\test_' + str(i+1) + '\\I\\' + file.split('/')[-1])
else:
try:
shutil.copy(file, '.\\C\\K10\\train_' + str(i+1) +'\\M\\'+file.split('/')[-1])
shutil.copy(file.replace('img', 'compound'),'.\\C\\K10\\train_' + str(i+1) + '\\I\\' + file.split('/')[-1])
except Exception:
print(file)
print(i+1)
os.makedirs('.\\C\\K10\\train_'+str(i+1) +'\\M\\')
shutil.copy(file, '.\\C\\K10\\train_'+str(i+1) + '\\M\\' +file.split('/')[-1])
os.makedirs('.\\C\\K10\\train_' + str(i+1) + '\\I\\' )
shutil.copy(file.replace('compound', 'img'),'.\\C\\K10\\train_' + str(i+1) + '\\I\\' + file.split('/')[-1])
get_data_crop(10)
边栏推荐
- Pdf file download (the download name is the same as the file name)
- Jsonp non homologous interaction (click trigger)
- How do I delete an entity from symfony2
- Yum command
- Alicloud centos8.0 installing mysql8
- Read multiple associations from a field using delimiters in laravel
- ActiveMQ--CVE-2016-3088
- Yaml configuration
- PostgreSQL user role permissions
- 2.15(Multiple of 3 Or 5)
猜你喜欢

Redis core article: the secret that can only be broken quickly

Panda weekly -2022/02/18

Avoid material "minefields"! Play super high conversion rate

Hdoj topic 2005 day

Using flex to implement the Holy Grail layout is as simple as that

DARKHOLE 2

Applet password input box

Wechat applet cloud function does not have dependency option installed

Determine whether it is a web page opened on wechat

Teach you how to add custom controls to a map
随机推荐
Pta--7-20 exchange minimum and maximum (15 points)
2.17(Avoid The Lakes)
Is it safe to open a new bond securities account
Arduino ide + esp8266+mqtt subscribe to publish temperature and humidity information
<C>. Figure guessing game
PAT B1063
wooyun-2014-065513
PAT B1081
Wechat applet swiper simple local picture display appears large blank
PAT B1057
Web components - Basics
Bloom filter
Mqtt+ardunio+esp8266 development (excluding mqtt server deployment)
Appearance of object attributes
DataX script task development record
通过启牛学堂开的股票账户可以用吗?资金安全吗?
Alicloud centos8.0 installing mysql8
PHP FPM, workman, spoole, golang simple performance test
Vulnhub range - correlation:2
Life cycle function of composite API