Keras Build dataset
Build dataset
- 1. Gewünschte Struktur-Verzeichniss (Varinate 1)
- 2. Gewünschte Struktur-Verzeichniss (Varinate 2)
- Referenzen:
import numpy as np
import tensorflow as tf
import os
import glob
import argparse
import random
import importlib
#from resnet import ResNet
import matplotlib.pyplot as plt
from pysim import config
importlib.reload(config)
import glob
import cv2
import shutil
from sklearn.preprocessing import LabelBinarizer
from sklearn.model_selection import train_test_split
1. Gewünschte Struktur-Verzeichniss (Varinate 1)
-
flow_from_directory - Struktur
- TRAIN: data/train/class1/jpg, data/train/class2/jpg - VAL: data/val/class1/jpg, data/val/class2/jpg - TEST: data/test/class1/jpg, data/test/class2/jpg
-
In diesem Datensazt sind die Daten schon in Train, Val, Test verteilt
for split in (config.TRAIN, config.VAL, config.TEST):
print("[INFO] processing '{} split'...".format(split))
imagePaths = glob.glob(os.path.sep.join([config.ORIG_INPUT_DATASET, split, '*']))
for imagePath in imagePaths:
filename = imagePath.split(os.path.sep)[-1]
label = config.CLASSES[int(filename.split("_")[0])]
#new directory path
newPath = os.path.sep.join([config.BASE_PATH, split, label])
# if directory doesn't exist than creat new
if not os.path.exists(newPath):
os.makedirs(newPath)
newPathFile = os.path.sep.join([newPath, filename])
shutil.copy2(imagePath, newPath)
filesPaths = glob.glob(os.path.sep.join([config.BASE_PATH, "*", "*"]))
data = []
labels = []
for imagePath in filesPaths:
label = imagePath.split(os.path.sep)[-2]
image = cv2.imread(imagePath)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (128, 128))
data.append(image)
labels.append(label)
Referenzen:
Adrian Rosebrock, OpenCV Face Recognition, PyImageSearch, https://www.pyimagesearch.com/, accessed on 3 January, 2021> www:https://www.pyimagesearch.com/2019/05/20/transfer-learning-with-keras-and-deep-learning/