neural_network #4
25
src/machine_learning/neural_network/database.py
Normal file
25
src/machine_learning/neural_network/database.py
Normal file
@ -0,0 +1,25 @@
|
||||
import os
|
||||
|
||||
import cv2
|
||||
|
||||
IMG_SIZE = 28
|
||||
CATEGORIES = ["bomby", "other"]
|
||||
|
||||
temp_path = os.path.abspath('../../..')
|
||||
DIR = 'images\learning'
|
||||
DIR = os.path.join(temp_path, DIR)
|
||||
|
||||
|
||||
def create_training_data():
|
||||
training_data = []
|
||||
for category in CATEGORIES:
|
||||
path = os.path.join(DIR, category)
|
||||
category_index = CATEGORIES.index(category)
|
||||
for img in os.listdir(path):
|
||||
try:
|
||||
img_array = cv2.imread(os.path.join(path, img), cv2.IMREAD_GRAYSCALE)
|
||||
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
|
||||
training_data.append((new_array, category_index))
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return training_data
|
@ -1,27 +0,0 @@
|
||||
import numpy as np
|
||||
import os
|
||||
import cv2
|
||||
|
||||
IMG_SIZE = 28
|
||||
CATEGORIES = ["bomby","other"]
|
||||
|
||||
temp_path =os.path.abspath('../..')
|
||||
DIR = 'images\learning'
|
||||
DIR = os.path.join(temp_path, DIR)
|
||||
|
||||
|
||||
def create_training_data():
|
||||
training_data_label = []
|
||||
training_data_images = []
|
||||
for category in CATEGORIES:
|
||||
path = os.path.join(DIR, category)
|
||||
category_index = CATEGORIES.index(category)
|
||||
for img in os.listdir(path):
|
||||
try:
|
||||
img_array = cv2.imread(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
|
||||
new_array = cv2.resize(img_array, (IMG_SIZE,IMG_SIZE))
|
||||
training_data_label.append(category_index)
|
||||
training_data_images.append(new_array)
|
||||
except Exception as e:
|
||||
pass
|
||||
return [training_data_images, training_data_label]
|
Loading…
Reference in New Issue
Block a user