Commit 37aca0a6 authored by Jonas Müller's avatar Jonas Müller

preparation for cross validation

parent 16d56240
20190523_095717.jpg,1578,1663,1921,1900,caries
20190523_095717.jpg,1694,2000,1784,2080,caries
20190523_111037.jpg,1003,1663,1182,1747,caries
20190523_111037.jpg,982,1742,1293,1890,caries
20190523_111037.jpg,1256,2053,1388,2164,caries
IMG_20190404_103747.jpg,2398,1227,2523,1346,caries
IMG_20190404_103747.jpg,3400,1254,3515,1346,caries
IMG_20190223_110731.jpg,292,330,444,397,caries
IMG_20190223_110731.jpg,272,399,388,502,caries
IMG_20190223_110731.jpg,326,669,508,785,caries
IMG_20190223_110731.jpg,1378,313,1511,412,caries
IMG_20190223_110731.jpg,1228,641,1425,815,caries
IMG_20190223_110731.jpg,780,932,847,1025,caries
IMG_20190404_123358.jpg,1032,2072,1336,2312,caries
IMG_20190404_123358.jpg,1384,2064,1616,2248,caries
IMG_20190404_123358.jpg,848,3200,1112,3400,caries
IMG_20190404_123358.jpg,1152,3384,1408,3600,caries
IMG_20190404_121332.jpg,896,1792,1152,2048,caries
IMG_20190404_121332.jpg,608,2904,776,3064,caries
IMG_20190330_101819.jpg,1489,703,1902,983,caries
IMG_20190330_101819.jpg,1153,1190,1254,1314,caries
IMG_20190330_101819.jpg,1383,1172,1507,1323,caries
IMG_20190330_101819.jpg,3166,896,3396,1296,caries
IMG_20190330_101819.jpg,3244,1342,3602,1778,caries
IMG_20190330_101819.jpg,1342,1071,1438,1158,caries
20190523_095739.jpg,401,976,718,1203,caries
20190523_095739.jpg,2481,1504,2597,1620,caries
20190523_101016.jpg,1853,1193,2254,1467,caries
20190523_101812.jpg,1446,1108,1673,1277,caries
IMG_20190404_125829.jpg,2881,1847,2945,1911,caries
IMG_20190404_125829.jpg,1507,1787,1585,1847,caries
IMG_20190404_125829.jpg,2867,1957,2941,2017,caries
20190510_114803.jpg,2523,1647,2855,1921,caries
20190523_101051.jpg,1916,1172,2169,1283,caries
20190523_101051.jpg,2090,1283,2175,1367,caries
IMG_20190404_101939.jpg,1352,1616,1528,1784,caries
IMG_20190404_101939.jpg,1624,1768,1776,1872,caries
IMG_20190404_101939.jpg,1200,3408,1336,3528,caries
IMG_20190404_101939.jpg,448,1776,584,1888,caries
20190507_113350.jpg,1573,1430,1657,1620,caries
20190507_113350.jpg,1657,1441,1779,1594,caries
20190507_113350.jpg,2053,1378,2285,1636,caries
20190507_113350.jpg,2322,1446,2528,1647,caries
IMG_20190223_110731.jpg,292,330,444,397,caries
IMG_20190223_110731.jpg,272,399,388,502,caries
IMG_20190223_110731.jpg,326,669,508,785,caries
IMG_20190223_110731.jpg,1378,313,1511,412,caries
IMG_20190223_110731.jpg,1228,641,1425,815,caries
IMG_20190223_110731.jpg,780,932,847,1025,caries
IMG_20190404_123358.jpg,1032,2072,1336,2312,caries
IMG_20190404_123358.jpg,1384,2064,1616,2248,caries
IMG_20190404_123358.jpg,848,3200,1112,3400,caries
IMG_20190404_123358.jpg,1152,3384,1408,3600,caries
IMG_20190404_121332.jpg,896,1792,1152,2048,caries
IMG_20190404_121332.jpg,608,2904,776,3064,caries
20190523_095717.jpg,1578,1663,1921,1900,caries
20190523_095717.jpg,1694,2000,1784,2080,caries
20190523_111037.jpg,1003,1663,1182,1747,caries
20190523_111037.jpg,982,1742,1293,1890,caries
20190523_111037.jpg,1256,2053,1388,2164,caries
IMG_20190404_103747.jpg,2398,1227,2523,1346,caries
IMG_20190404_103747.jpg,3400,1254,3515,1346,caries
IMG_20190330_101819.jpg,1489,703,1902,983,caries
IMG_20190330_101819.jpg,1153,1190,1254,1314,caries
IMG_20190330_101819.jpg,1383,1172,1507,1323,caries
IMG_20190330_101819.jpg,3166,896,3396,1296,caries
IMG_20190330_101819.jpg,3244,1342,3602,1778,caries
IMG_20190330_101819.jpg,1342,1071,1438,1158,caries
20190523_095739.jpg,401,976,718,1203,caries
20190523_095739.jpg,2481,1504,2597,1620,caries
20190523_101016.jpg,1853,1193,2254,1467,caries
20190523_101812.jpg,1446,1108,1673,1277,caries
IMG_20190404_125829.jpg,2881,1847,2945,1911,caries
IMG_20190404_125829.jpg,1507,1787,1585,1847,caries
IMG_20190404_125829.jpg,2867,1957,2941,2017,caries
20190510_114803.jpg,2523,1647,2855,1921,caries
20190523_101051.jpg,1916,1172,2169,1283,caries
20190523_101051.jpg,2090,1283,2175,1367,caries
IMG_20190404_101939.jpg,1352,1616,1528,1784,caries
IMG_20190404_101939.jpg,1624,1768,1776,1872,caries
IMG_20190404_101939.jpg,1200,3408,1336,3528,caries
IMG_20190404_101939.jpg,448,1776,584,1888,caries
20190507_113350.jpg,1573,1430,1657,1620,caries
20190507_113350.jpg,1657,1441,1779,1594,caries
20190507_113350.jpg,2053,1378,2285,1636,caries
20190507_113350.jpg,2322,1446,2528,1647,caries
IMG_20190330_101819.jpg,1489,703,1902,983,caries
IMG_20190330_101819.jpg,1153,1190,1254,1314,caries
IMG_20190330_101819.jpg,1383,1172,1507,1323,caries
IMG_20190330_101819.jpg,3166,896,3396,1296,caries
IMG_20190330_101819.jpg,3244,1342,3602,1778,caries
IMG_20190330_101819.jpg,1342,1071,1438,1158,caries
20190523_095739.jpg,401,976,718,1203,caries
20190523_095739.jpg,2481,1504,2597,1620,caries
20190523_101016.jpg,1853,1193,2254,1467,caries
20190523_095717.jpg,1578,1663,1921,1900,caries
20190523_095717.jpg,1694,2000,1784,2080,caries
20190523_111037.jpg,1003,1663,1182,1747,caries
20190523_111037.jpg,982,1742,1293,1890,caries
20190523_111037.jpg,1256,2053,1388,2164,caries
IMG_20190404_103747.jpg,2398,1227,2523,1346,caries
IMG_20190404_103747.jpg,3400,1254,3515,1346,caries
IMG_20190223_110731.jpg,292,330,444,397,caries
IMG_20190223_110731.jpg,272,399,388,502,caries
IMG_20190223_110731.jpg,326,669,508,785,caries
IMG_20190223_110731.jpg,1378,313,1511,412,caries
IMG_20190223_110731.jpg,1228,641,1425,815,caries
IMG_20190223_110731.jpg,780,932,847,1025,caries
IMG_20190404_123358.jpg,1032,2072,1336,2312,caries
IMG_20190404_123358.jpg,1384,2064,1616,2248,caries
IMG_20190404_123358.jpg,848,3200,1112,3400,caries
IMG_20190404_123358.jpg,1152,3384,1408,3600,caries
IMG_20190404_121332.jpg,896,1792,1152,2048,caries
IMG_20190404_121332.jpg,608,2904,776,3064,caries
20190523_101812.jpg,1446,1108,1673,1277,caries
IMG_20190404_125829.jpg,2881,1847,2945,1911,caries
IMG_20190404_125829.jpg,1507,1787,1585,1847,caries
IMG_20190404_125829.jpg,2867,1957,2941,2017,caries
20190510_114803.jpg,2523,1647,2855,1921,caries
20190523_101051.jpg,1916,1172,2169,1283,caries
20190523_101051.jpg,2090,1283,2175,1367,caries
IMG_20190404_101939.jpg,1352,1616,1528,1784,caries
IMG_20190404_101939.jpg,1624,1768,1776,1872,caries
IMG_20190404_101939.jpg,1200,3408,1336,3528,caries
IMG_20190404_101939.jpg,448,1776,584,1888,caries
20190507_113350.jpg,1573,1430,1657,1620,caries
20190507_113350.jpg,1657,1441,1779,1594,caries
20190507_113350.jpg,2053,1378,2285,1636,caries
20190507_113350.jpg,2322,1446,2528,1647,caries
20190523_101812.jpg,1446,1108,1673,1277,caries
IMG_20190404_125829.jpg,2881,1847,2945,1911,caries
IMG_20190404_125829.jpg,1507,1787,1585,1847,caries
IMG_20190404_125829.jpg,2867,1957,2941,2017,caries
20190510_114803.jpg,2523,1647,2855,1921,caries
20190523_095717.jpg,1578,1663,1921,1900,caries
20190523_095717.jpg,1694,2000,1784,2080,caries
20190523_111037.jpg,1003,1663,1182,1747,caries
20190523_111037.jpg,982,1742,1293,1890,caries
20190523_111037.jpg,1256,2053,1388,2164,caries
IMG_20190404_103747.jpg,2398,1227,2523,1346,caries
IMG_20190404_103747.jpg,3400,1254,3515,1346,caries
IMG_20190223_110731.jpg,292,330,444,397,caries
IMG_20190223_110731.jpg,272,399,388,502,caries
IMG_20190223_110731.jpg,326,669,508,785,caries
IMG_20190223_110731.jpg,1378,313,1511,412,caries
IMG_20190223_110731.jpg,1228,641,1425,815,caries
IMG_20190223_110731.jpg,780,932,847,1025,caries
IMG_20190404_123358.jpg,1032,2072,1336,2312,caries
IMG_20190404_123358.jpg,1384,2064,1616,2248,caries
IMG_20190404_123358.jpg,848,3200,1112,3400,caries
IMG_20190404_123358.jpg,1152,3384,1408,3600,caries
IMG_20190404_121332.jpg,896,1792,1152,2048,caries
IMG_20190404_121332.jpg,608,2904,776,3064,caries
IMG_20190330_101819.jpg,1489,703,1902,983,caries
IMG_20190330_101819.jpg,1153,1190,1254,1314,caries
IMG_20190330_101819.jpg,1383,1172,1507,1323,caries
IMG_20190330_101819.jpg,3166,896,3396,1296,caries
IMG_20190330_101819.jpg,3244,1342,3602,1778,caries
IMG_20190330_101819.jpg,1342,1071,1438,1158,caries
20190523_095739.jpg,401,976,718,1203,caries
20190523_095739.jpg,2481,1504,2597,1620,caries
20190523_101016.jpg,1853,1193,2254,1467,caries
20190523_101051.jpg,1916,1172,2169,1283,caries
20190523_101051.jpg,2090,1283,2175,1367,caries
IMG_20190404_101939.jpg,1352,1616,1528,1784,caries
IMG_20190404_101939.jpg,1624,1768,1776,1872,caries
IMG_20190404_101939.jpg,1200,3408,1336,3528,caries
IMG_20190404_101939.jpg,448,1776,584,1888,caries
20190507_113350.jpg,1573,1430,1657,1620,caries
20190507_113350.jpg,1657,1441,1779,1594,caries
20190507_113350.jpg,2053,1378,2285,1636,caries
20190507_113350.jpg,2322,1446,2528,1647,caries
20190523_101051.jpg,1916,1172,2169,1283,caries
20190523_101051.jpg,2090,1283,2175,1367,caries
IMG_20190404_101939.jpg,1352,1616,1528,1784,caries
IMG_20190404_101939.jpg,1624,1768,1776,1872,caries
IMG_20190404_101939.jpg,1200,3408,1336,3528,caries
IMG_20190404_101939.jpg,448,1776,584,1888,caries
20190507_113350.jpg,1573,1430,1657,1620,caries
20190507_113350.jpg,1657,1441,1779,1594,caries
20190507_113350.jpg,2053,1378,2285,1636,caries
20190507_113350.jpg,2322,1446,2528,1647,caries
20190523_095717.jpg,1578,1663,1921,1900,caries
20190523_095717.jpg,1694,2000,1784,2080,caries
20190523_111037.jpg,1003,1663,1182,1747,caries
20190523_111037.jpg,982,1742,1293,1890,caries
20190523_111037.jpg,1256,2053,1388,2164,caries
IMG_20190404_103747.jpg,2398,1227,2523,1346,caries
IMG_20190404_103747.jpg,3400,1254,3515,1346,caries
IMG_20190223_110731.jpg,292,330,444,397,caries
IMG_20190223_110731.jpg,272,399,388,502,caries
IMG_20190223_110731.jpg,326,669,508,785,caries
IMG_20190223_110731.jpg,1378,313,1511,412,caries
IMG_20190223_110731.jpg,1228,641,1425,815,caries
IMG_20190223_110731.jpg,780,932,847,1025,caries
IMG_20190404_123358.jpg,1032,2072,1336,2312,caries
IMG_20190404_123358.jpg,1384,2064,1616,2248,caries
IMG_20190404_123358.jpg,848,3200,1112,3400,caries
IMG_20190404_123358.jpg,1152,3384,1408,3600,caries
IMG_20190404_121332.jpg,896,1792,1152,2048,caries
IMG_20190404_121332.jpg,608,2904,776,3064,caries
IMG_20190330_101819.jpg,1489,703,1902,983,caries
IMG_20190330_101819.jpg,1153,1190,1254,1314,caries
IMG_20190330_101819.jpg,1383,1172,1507,1323,caries
IMG_20190330_101819.jpg,3166,896,3396,1296,caries
IMG_20190330_101819.jpg,3244,1342,3602,1778,caries
IMG_20190330_101819.jpg,1342,1071,1438,1158,caries
20190523_095739.jpg,401,976,718,1203,caries
20190523_095739.jpg,2481,1504,2597,1620,caries
20190523_101016.jpg,1853,1193,2254,1467,caries
20190523_101812.jpg,1446,1108,1673,1277,caries
IMG_20190404_125829.jpg,2881,1847,2945,1911,caries
IMG_20190404_125829.jpg,1507,1787,1585,1847,caries
IMG_20190404_125829.jpg,2867,1957,2941,2017,caries
20190510_114803.jpg,2523,1647,2855,1921,caries
import copy
import os
import random
from optparse import OptionParser
from pathlib import Path
from keras_frcnn.simple_parser import get_data
def split(a, n):
k, m = divmod(len(a), n)
return (a[i * k + min(i, m):(i + 1) * k + min(i + 1, m)] for i in range(n))
parser = OptionParser()
parser.add_option("-p", "--path", dest="annotation_all", help="Reference to file with all annotated images and bboxes. (Simple Format needed)")
parser.add_option("-n", "--num_folds", type="int", dest="num_folds",
help="Number of folds for the dataset. ", default=5)
(options, args) = parser.parse_args()
output_path = 'data/cross_validate/'
if not options.annotation_all: # if filename is not given
parser.error('Error: path to annotation file data must be specified. Pass --path to command line')
all_data, classes_count, class_mapping = get_data(options.annotation_all)
file_path_dict = {}
for idx, entry in enumerate(all_data):
file_path_dict[idx] = (Path(entry['filepath']).name, entry['filepath'])
print(file_path_dict)
# list of indexes representing where each number represents one image
images = list(range(len(file_path_dict.keys())))
# shuffle the data
random.shuffle(images)
fold = list(split(images, options.num_folds))
print(fold)
train = {}
test = {}
for i in range(len(fold)):
test[i] = copy.deepcopy(fold[i])
for j in range(len(fold)):
if i != j:
if i not in train.keys():
train[i] = copy.deepcopy(fold[j])
else:
train[i].extend(fold[j])
#visualize what was done:
'''
for i in range(len(fold)):
print('train')
print(train[i])
print('test')
print(test[i])
print()
'''
for i in range(len(fold)):
new_dir = output_path+'fold_'+str(i)
if not os.path.exists(new_dir):
os.makedirs(new_dir)
with open(new_dir+'/annotations_test.txt', 'w') as file:
lines = []
for filenumber in test[i]:
for box in all_data[filenumber]['bboxes']:
lines.append(file_path_dict[filenumber][0] + ',' + str(box['x1']) + ',' + str(box['y1']) + ',' + str(box['x2']) + ',' + str(box['y2']) + ',' +box['class']+ '\n')
file.writelines(lines)
with open(new_dir+'/annotations_train.txt', 'w') as file:
lines = []
for filenumber in train[i]:
for box in all_data[filenumber]['bboxes']:
lines.append(file_path_dict[filenumber][0] + ',' + str(box['x1']) + ',' + str(box['y1']) + ',' + str(box['x2']) + ',' + str(box['y2']) + ',' +box['class']+ '\n')
file.writelines(lines)
\ No newline at end of file
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