Created
November 15, 2019 20:24
-
-
Save colleenDunlap/69b5cfe04a64339ef7d2191b9a9f6d6f to your computer and use it in GitHub Desktop.
Simple Python Script for allocating 20% of files in a folder to Testing Set, and the remainder to a Training Set
This file contains 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
import os | |
directory = os.fsencode(r"C:\Users\Colleen Dunlap\Desktop\_flowers\tulip") | |
numPics = 0 | |
for file in os.listdir(directory): | |
filename = os.fsdecode(file) | |
print(r"C:/Users/Colleen Dunlap/Desktop/_flowers/tulip/" + filename) | |
if filename.endswith(".jpg"): | |
numPics +=1 | |
if numPics % 4 == 0: #put in testing | |
os.replace(r"C:/Users/Colleen Dunlap/Desktop/_flowers/tulip/" + filename, r"C:/Users/Colleen Dunlap/Desktop/_flowers/testing/tulip/" + filename) | |
else:#put in training | |
os.replace(r"C:/Users/Colleen Dunlap/Desktop/_flowers/tulip/" + filename, r"C:/Users/Colleen Dunlap/Desktop/_flowers/training/tulip/" + filename) | |
continue | |
else: | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment