Created
June 1, 2020 11:10
-
-
Save ggosiang/98cb1d7e8ff2f8ae1bcebf2481739d6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"853\n" | |
] | |
} | |
], | |
"source": [ | |
"import glob, cv2, os\n", | |
"\n", | |
"img_list = glob.glob('/datasets/face-mask-detection/images/*.png')\n", | |
"print(len(img_list))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"767\n", | |
"Output to train.txt\n" | |
] | |
} | |
], | |
"source": [ | |
"path_prefix = \"/project/a-team/darknet/data/face-mask-detection/\"\n", | |
"\n", | |
"train_samples = int(len(img_list)*0.9)\n", | |
"print(train_samples)\n", | |
"\n", | |
"file = open(os.path.join(path_prefix, \"train.txt\"), \"a\")\n", | |
"for i in range(train_samples): # train: 0 ~ 766\n", | |
" img = cv2.imread(img_list[i])\n", | |
" filename = img_list[i].split('/')[-1].replace('.png', '.jpg')\n", | |
" cv2.imwrite(\n", | |
" os.path.join(path_prefix+\"dataset\", filename),\n", | |
" img, \n", | |
" [int(cv2.IMWRITE_JPEG_QUALITY), 100])\n", | |
" file.write(\"data/face-mask-detection/dataset/%s\\n\" % filename)\n", | |
"file.close()\n", | |
"print(\"Output to train.txt\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Output to valid.txt\n" | |
] | |
} | |
], | |
"source": [ | |
"file = open(os.path.join(path_prefix, \"valid.txt\"), \"a\")\n", | |
"for i in range(train_samples, len(img_list)): # train: 767 ~ 852\n", | |
" img = cv2.imread(img_list[i])\n", | |
" filename = img_list[i].split('/')[-1].replace('.png', '.jpg')\n", | |
" cv2.imwrite(\n", | |
" os.path.join(path_prefix+\"dataset\", filename),\n", | |
" img, \n", | |
" [int(cv2.IMWRITE_JPEG_QUALITY), 100])\n", | |
" file.write(\"data/face-mask-detection/dataset/%s\\n\" % filename)\n", | |
"file.close()\n", | |
"print(\"Output to valid.txt\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment