Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Mon Nov 18 17:27:00 2019
- @author: Skosko
- """
- base = r"C:\Users\gustafsson\Desktop\PR&ML-HT"
- import os
- import cv2
- class_names =sorted(os.listdir(r"C:\Users\gustafsson\Desktop\PR&ML-HT\train\train"))
- stats = {}
- for item in class_names:
- if not os.path.exists(base + os.sep + "clean_train" + os.sep + item):
- print("Create directories for classes...")
- os.makedirs(base + os.sep + "clean_train" + os.sep + item)
- stats[item] = 0
- for root, dirs, files in os.walk(r"C:\Users\gustafsson\Desktop\PR&ML-HT\train\train"):
- print(root)
- for name in files:
- if name.endswith(".jpg"):
- # Load the image:
- img = cv2.imread(root + os.sep + name, cv2.IMREAD_UNCHANGED)
- # Resize it to the net input size:
- img = cv2.resize(img, (224,224))
- label = root.split(os.sep)[-1]
- cv2.imwrite(base + os.sep + "clean_train" + os.sep + label + os.sep + name, img)
- stats[label] += 1
- print(label, ":", stats[label])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement