AI_PRO/createNeuralNetworkDatabase.py

48 lines
1.5 KiB
Python
Raw Normal View History

2021-06-01 22:47:53 +02:00
import os
import cv2
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
2021-06-22 22:56:01 +02:00
import pandas as pd
from matplotlib.pyplot import imshow
2021-06-01 22:47:53 +02:00
path_potatoes = 'neural_network\\images\\potatoes'
path_beetroot = 'neural_network\\images\\beetroot'
2021-06-22 22:56:01 +02:00
size = 100
2021-06-01 22:47:53 +02:00
#POTATOES
2021-06-22 22:56:01 +02:00
image_data = []
label_data = []
2021-06-01 22:47:53 +02:00
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))
2021-06-22 22:56:01 +02:00
image_data.append([pic])
label_data.append(1)
2021-06-01 22:47:53 +02:00
2021-06-22 22:56:01 +02:00
#np.save(os.path.join('neural_network','potatoes-dataset'),np.array(training_data_potatoes))
2021-06-02 01:32:48 +02:00
2021-06-22 22:56:01 +02:00
#saved_potatoes = np.load(os.path.join('neural_network','potatoes-dataset.npy'))
2021-06-01 22:47:53 +02:00
#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))
2021-06-22 22:56:01 +02:00
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'))
2021-06-01 22:47:53 +02:00
2021-06-22 22:56:01 +02:00
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))
2021-06-01 22:47:53 +02:00
2021-06-22 22:56:01 +02:00
saved_images = np.load(os.path.join('neural_network','image-dataset.npy'))
2021-06-01 22:47:53 +02:00
2021-06-22 22:56:01 +02:00
print(saved_images.shape)
2021-06-02 01:32:48 +02:00
2021-06-22 22:56:01 +02:00
plt.imshow(saved_images[0].reshape(size,size,3))
plt.imshow(np.array(image_data[0]).reshape(size,size,3))
plt.show()