-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_project.py
More file actions
51 lines (34 loc) · 1.32 KB
/
my_project.py
File metadata and controls
51 lines (34 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
from keras.preprocessing.image import *
import numpy as np
import matplotlib as plt
import os
import random
from glob import glob
from notesClassifier import cnn_model
# Model
classifer = cnn_model()
classifier.load_weights('notesClassifier.h5')
#check model performance on random images
img_path = random.choice(glob('notes/*'))
img = load_img(img_path, target_size = (124, 124, 3)) # this is an PIL image
x = img_to_array(img)/255.0
y = classifier.predict(np.expand_dims(x, axis = 0))
print(np.squeeze(y) < 0.5)
# PREDICTION
def prediction(file_path):
img = load_img(file_path, target_size = (124, 124, 3))
x = img_to_array(img)/255.0
y = classifier.predict(np.expand_dims(x, axis = 0))
return np.squeeze(y) < 0.5
# create 'notes' folder to store extracted notes image
if not os.path.exists(r'C:\Users\Himanshu\Desktop\testDataSet\notes'):
os.mkdir(r'C:\Users\Himanshu\Desktop\testDataSet\notes')
# get filepaths
files = glob(r'C:\Users\Himanshu\Desktop\testDataSet/*.*')
for file_path in files:
if prediction(file_path):
file_name = ( file_path.split("testDataSet")[1])
file_name = file_name[1:]
print(file_name)
os.rename(file_path,r'C:\Users\Himanshu\Desktop\testDataSet\notes/' + file_name)