AI_PRO/createNeuralNetworkDatabase.py
2021-06-22 22:56:01 +02:00

48 lines
1.5 KiB
Python

import os
import cv2
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib.pyplot import imshow
path_potatoes = 'neural_network\\images\\potatoes'
path_beetroot = 'neural_network\\images\\beetroot'
size = 100
#POTATOES
image_data = []
label_data = []
for img in os.listdir(path_potatoes):
pic = cv2.imread(os.path.join(path_potatoes,img))
pic = cv2.cvtColor(pic,cv2.COLOR_BGR2RGB)
pic = cv2.resize(pic,(size,size))
image_data.append([pic])
label_data.append(1)
#np.save(os.path.join('neural_network','potatoes-dataset'),np.array(training_data_potatoes))
#saved_potatoes = np.load(os.path.join('neural_network','potatoes-dataset.npy'))
#BEETROOT
for img in os.listdir(path_beetroot):
pic = cv2.imread(os.path.join(path_beetroot,img))
pic = cv2.cvtColor(pic,cv2.COLOR_BGR2RGB)
pic = cv2.resize(pic,(size,size))
image_data.append([pic])
label_data.append(0)
#np.save(os.path.join('neural_network','beetroot-dataset'),np.array(training_data_beetroot))
#saved_potatoes = np.load(os.path.join('neural_network','beetroot-dataset.npy'))
np.save(os.path.join('neural_network','image-dataset'),np.array(image_data))
np.save(os.path.join('neural_network','label-dataset'),np.array(label_data))
saved_images = np.load(os.path.join('neural_network','image-dataset.npy'))
print(saved_images.shape)
plt.imshow(saved_images[0].reshape(size,size,3))
plt.imshow(np.array(image_data[0]).reshape(size,size,3))
plt.show()