학습한 내용
import os
import glob
data_path='./da'
train_data_path=data_path+'/train'
train_ano_path=data_path+'/trainano'
val_data_path=data_path+'/Validation'
val_ano_path=data_path+'/validano'
# 라벨별로 분류가 되어있지 않은 데이터 및 json파일
# chinese-cabbage가 '_'가 아닌 '-'로 나뉘어져있어 파일명을 '_'로 split했을때 문제가 생기므로 파일명 변환
files = glob.glob(train_data_path + '/*')
for f in files:
newfiles=f.replace("-","_")
os.rename(f, newfiles)
files = glob.glob(train_ano_path + '/*')
for f in files:
newfiles=f.replace("-","_")
os.rename(f, newfiles)
files = glob.glob(val_data_path + '/*')
for f in files:
newfiles=f.replace("-","_")
os.rename(f, newfiles)
files = glob.glob(val_ano_path + '/*')
for f in files:
newfiles=f.replace("-","_")
os.rename(f, newfiles)
#파일명에 맞춰 품목,품종,등급으로 폴더를 만들고 이미지나 json파일을 옮김
for root, dirs, files in os.walk(train_data_path):
for file in files:
label = file.split('_')[0]
lowlabel=file.split('_')[1]
grade=file.split('_')[2]
train_path = './data'+'/train'+'/image'+'/'+label+lowlabel+grade
if not os.path.exists(train_path):
os.makedirs(train_path)
os.rename(train_data_path +'/' +file, train_path +'/' +file)
for root, dirs, files in os.walk(train_ano_path):
for file in files:
label = file.split('_')[0]
lowlabel=file.split('_')[1]
grade=file.split('_')[2]
train_label_path = './data'+'/train'+'/label'+'/'+label+lowlabel+grade
if not os.path.exists(train_label_path):
os.makedirs(train_label_path)
os.rename(train_ano_path +'/' +file, train_label_path +'/' +file)
for root, dirs, files in os.walk(val_data_path):
for file in files:
label = file.split('_')[0]
lowlabel=file.split('_')[1]
grade=file.split('_')[2]
val_path = './data'+'\\val'+'/image'+'/'+label+lowlabel+grade
if not os.path.exists(val_path):
os.makedirs(val_path)
os.rename(val_data_path +'/' +file, val_path +'/' +file)
for root, dirs, files in os.walk(val_ano_path):
for file in files:
label = file.split('_')[0]
lowlabel=file.split('_')[1]
grade=file.split('_')[2]
val_label_path = './data'+'/val'+'/label'+'/'+label+lowlabel+grade
if not os.path.exists(val_label_path):
os.makedirs(val_label_path)
os.rename(val_ano_path +'/' +file, val_label_path +'/' +file)
#radish_winter_radish로 등급이 나뉘지않은채로 분류되어 다시 작업
for root, dirs, files in os.walk('./data/train/label/radishwinterradish'):
for file in files:
label = file.split('_')[0]
lowlabel=file.split('_')[1]
lowlabel1=file.split('_')[2]
grade=file.split('_')[3]
pathss = './data'+'/train'+'/label'+'/'+label+lowlabel+lowlabel1+grade
if not os.path.exists(pathss):
os.makedirs(pathss)
os.rename('./data/train/label/radishwinterradish' +'/' +file, pathss +'/' +file)
for root, dirs, files in os.walk('./data/val/image/radishwinterradish'):
for file in files:
label = file.split('_')[0]
lowlabel=file.split('_')[1]
lowlabel1=file.split('_')[2]
grade=file.split('_')[3]
pathss = './data'+'/val'+'/image'+'/'+label+lowlabel+lowlabel1+grade
if not os.path.exists(pathss):
os.makedirs(pathss)
os.rename('./data/val/image/radishwinterradish' +'/' +file, pathss +'/' +file)
for root, dirs, files in os.walk('./data/val/label/radishwinterradish'):
for file in files:
label = file.split('_')[0]
lowlabel=file.split('_')[1]
lowlabel1=file.split('_')[2]
grade=file.split('_')[3]
pathss = './data'+'/val'+'/label'+'/'+label+lowlabel+lowlabel1+grade
if not os.path.exists(pathss):
os.makedirs(pathss)
os.rename('./data/val/label/radishwinterradish' +'/' +file, pathss +'/' +file)
for root, dirs, files in os.walk('./data/train/image/radishwinterradish'):
for file in files:
label = file.split('_')[0]
lowlabel=file.split('_')[1]
lowlabel1=file.split('_')[2]
grade=file.split('_')[3]
pathss = './data'+'/train'+'/image'+'/'+label+lowlabel+lowlabel1+grade
if not os.path.exists(pathss):
os.makedirs(pathss)
os.rename('./data/train/image/radishwinterradish' +'/' +file, pathss +'/' +file)
실행결과
품목+품종+등급별로 폴더를 만들었고
모델 학습에서 등급까지 분류할수 있도록 하려고 한다.
학습한 내용 중 어려웠던 점 또는 해결못한 것들
해결방법 작성
학습 소감
나중에 모델학습시에 등급이 다른것까지 분류할수있을지 궁금하다.