diff --git a/scripts/data.py b/scripts/data.py new file mode 100644 index 0000000..26af797 --- /dev/null +++ b/scripts/data.py @@ -0,0 +1,64 @@ +import sys +import tempfile +import os.path +import os +import shutil + +print(sys.argv[-1]) + +if sys.argv[-1] == 'data.py' or 'data.yaml' not in sys.argv[-1]: + print('Please provide a path to a data.yaml file') + exit(1) + +filePath = sys.argv[-1] +data = [] +basePath = os.path.dirname(filePath) +trainPath = os.path.join(basePath, 'train', 'images') +validPath = os.path.join(basePath, 'valid', 'images') +testPath = os.path.join(basePath, 'test', 'images') + +if not os.path.exists(basePath): + print(f'Dataset directory {basePath} doesn\'t exist') + exit(2) + +if not os.path.exists(trainPath): + print(f'Dataset directory {trainPath} doesn\'t exist') + exit(2) + +if not os.path.exists(validPath): + print(f'Dataset directory {validPath} doesn\'t exist') + exit(2) + +if not os.path.exists(testPath): + print(f'Dataset directory {testPath} doesn\'t exist') + exit(2) + +def isInList (match, l) : + for i in l: + if match in i: + return True + return False + +with open(filePath, 'r') as file: + lines = file.readlines() + for line in lines: + if 'train: ' in line: + data.append(f'train: {trainPath}{os.linesep}') + elif 'val: ' in line: + data.append(f'val: {validPath}{os.linesep}') + elif 'test: ' in line: + data.append(f'test: {testPath}{os.linesep}') + else: + data.append(line) + if not isInList('train: ', data): + data.append(f'train: {trainPath}{os.linesep}') + elif not isInList('val: ', data): + data.append(f'val: {validPath}{os.linesep}') + elif not isInList('test: ', data): + data.append(f'test: {testPath}{os.linesep}') + file.close() + +with tempfile.NamedTemporaryFile() as tmp: + with open(tmp.name, 'w') as t: + t.writelines(data) + shutil.copy(tmp.name, filePath) diff --git a/scripts/train.sh b/scripts/train.sh index 5f01eae..891473c 100644 --- a/scripts/train.sh +++ b/scripts/train.sh @@ -47,4 +47,4 @@ if [ ! -f "${UNZIPPED}/data.yaml" ]; then fi FULLDEST=$(realpath "${DEST}") - +python scripts/data.py "${FULLDEST}/data.yaml" diff --git a/views/index.html b/views/index.html index 4eafaec..492b9fb 100755 --- a/views/index.html +++ b/views/index.html @@ -5,7 +5,9 @@

@@ -17,4 +19,4 @@
- \ No newline at end of file +