Commit cf9e1be5 authored by Gilberto Astolfi's avatar Gilberto Astolfi
Browse files

adicionando estrutura voc2007

parent 1e0f81f2
......@@ -361,6 +361,7 @@ class DataAugmentation:
def oversampling(self):
print('Iniciando oversampling...')
print(self.root_path)
folds = os.listdir(self.root_path)
for fold in folds:
path_train = self.root_path + '/' + fold + '/train'
......
import os
import glob
from shutil import copyfile, rmtree
import argparse
def criar_diretorio(path_dir):
if not os.path.exists(path_dir):
os.makedirs(path_dir)
def remove_VOC(path_fold_voc):
if os.path.exists(path_fold_voc):
print('Removendo estrutura de pastas VOC2007')
rmtree(path_fold_voc, ignore_errors=True)
def criar_VOC(path_folds, path_fold_voc):
remove_VOC(path_fold_voc)
for pth in os.listdir(path_folds):
print('Criando estutura VOC2007 para: ' + pth)
path_ann = path_fold_voc + '/' + pth + '/VOC2007/Annotations'
path_jpg = path_fold_voc + '/' + pth + '/VOC2007/JPEGImages'
path_txt = path_fold_voc + '/' + pth + '/VOC2007/ImageSets/Main'
criar_diretorio(path_ann)
criar_diretorio(path_jpg)
criar_diretorio(path_txt)
path_fold = path_folds + '/' + pth
for pt_conjunto in os.listdir(path_fold):
pt_txt_conjunto = path_txt + '/' + pt_conjunto + '.txt'
path_conjunto = path_fold +'/'+ pt_conjunto
for cl in os.listdir(path_conjunto):
path_class = path_conjunto + '/' + cl
files = glob.glob(path_class+"/*")
for file in files:
basename = os.path.basename(file)
name, extension = os.path.splitext(basename)
if extension == '.jpg':
destino = path_jpg + '/' + basename
copyfile(file, destino)
elif extension == '.xml':
destino = path_ann + '/' + basename
copyfile(file, destino)
f = open(pt_txt_conjunto, 'a')
f.write(name+'\n')
f.close()
print('Finalizado a estutura VOC2007 para: ' + pth)
print('Finalizado a estutura VOC2007 para todas as folds.')
if __name__ == '__main__':
# python3 estruturaVOC2007.py ../fold ../out_fold_voc
parser = argparse.ArgumentParser()
parser.add_argument('path_in', metavar='path_in', type=str, help='A root directory where are folds.')
parser.add_argument('path_out', metavar='path_out', type=str, help='Path where the output will be created')
args = parser.parse_args()
path_in = args.path_in
path_out = args.path_out
criar_VOC(path_in, path_out)
\ No newline at end of file
......@@ -6,7 +6,7 @@ import argparse
if __name__ == '__main__':
# python3 main.py ./data/Pests3C1P ./data/folds repetition 30 True 0 True
# python3 main.py ../Pests4C2P ../folds cross 5 True 0 True
parser = argparse.ArgumentParser()
parser.add_argument('path_in', metavar='path_in', type=str, help='A root directory where are annotated images.')
parser.add_argument('path_out', metavar='path_out', type=str, help='Path where the output will be created')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment