diff --git a/boss_input.py b/boss_input.py index b97f37f..8c16333 100644 --- a/boss_input.py +++ b/boss_input.py @@ -61,7 +61,6 @@ def read_image(file_path): def extract_data(path): images, labels = traverse_dir(path) images = np.array(images) - dic = dict([(label, i) for i, label in enumerate(set(labels))]) - labels = np.array([dic[label] for label in labels]) + labels = np.array([0 if label.endswith('boss') else 1 for label in labels]) return images, labels diff --git a/boss_train.py b/boss_train.py index 3329c1f..441f25e 100644 --- a/boss_train.py +++ b/boss_train.py @@ -143,8 +143,10 @@ def predict(self, image): if image.shape != (1, 3, IMAGE_SIZE, IMAGE_SIZE): image = resize_with_pad(image) image = image.reshape((1, 3, IMAGE_SIZE, IMAGE_SIZE)) + result = self.model.predict_proba(image) + print(result) result = self.model.predict_classes(image) - # result = self.model.predict_proba(image) + return result[0] @@ -156,24 +158,30 @@ def evaluate(self, dataset): dataset = Dataset() dataset.read() - + """ model = Model() model.build_model(dataset) model.train(dataset, nb_epoch=10) model.save() - + """ model = Model() model.load() model.evaluate(dataset) - for image, label in zip(dataset.X_test, dataset.Y_test): - model.predict(image.reshape(1, 3, IMAGE_SIZE, IMAGE_SIZE)) - print(label) + #for image, label in zip(dataset.X_test, dataset.Y_test): + # model.predict(image.reshape(1, 3, IMAGE_SIZE, IMAGE_SIZE)) + # print(label) """ import cv2 import os - - #image = cv2.imread('./data/other/Abdel_Nasser_Assidi_0002.jpg') - + model = Model() + model.load() + image = cv2.imread('test.jpg') + image = resize_with_pad(image) + image = image.reshape((1, 3, IMAGE_SIZE, IMAGE_SIZE)) + result = model.predict(image) + print(result) + """ + """ for file_name in os.listdir('./data/boss'): if file_name.endswith('.jpg'): print(file_name) diff --git a/camera_reader.py b/camera_reader.py index b9f6fa0..8d10929 100644 --- a/camera_reader.py +++ b/camera_reader.py @@ -72,7 +72,8 @@ def run(self): model = Model() model.load() while True: - ret, frame = cap.read() + _, frame = cap.read() + # グレースケール変換 frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) @@ -90,11 +91,13 @@ def run(self): x, y = rect[0:2] width, height = rect[2:4] - image = frame[y-50: y + height, x: x + width + 50] - cv2.imwrite('test.jpg', image) + #image = frame[y - 50: y + height, x: x + width + 50] + image = frame[y - 50: y + height, x: x + width] + #image = frame[y: y + height, x: x + width] + #now = datetime.now().strftime('%Y%m%d%H%M%S') + #cv2.imwrite(now + '.jpg', image) result = model.predict(image) - print(result) - if result == 1: # boss + if result == 0: # boss print('Boss is approaching') show_image() else: