-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrain.py
83 lines (66 loc) · 2.05 KB
/
train.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
## Importing Dependencies
import os
import sys
import subprocess
import cv2
import random
import time
import test
import pyttsx
if __name__ == '__main__':
""" Either Train the model or Test it """
print("1. Train") # Enter 1 to train
print("2. Test") # Enter 2 to train
# Fucntion called
option = input("")
if option == "1":
pass
elif option == "2":
test.testimg()
exit()
else:
print("Invalid Option")
# Training class
class Training():
def __init__(self, human):
self.human = human
# To create a Folder with the New User
file_path = "D:/WorkArea/GitHub/tensorflow-for-poets-2/tf_files/Humans/" + self.human
# Check if the Folder exists, if not create a new folder
if not os.path.exists(file_path):
os.makedirs(file_path)
# Return the name of the person
def HUMAN(self):
return(self.human)
# Read the name of the person
tellmeyourname = input("Your Name: ")
human_me = Training(tellmeyourname) #Create an object with the name
# Generate a random number
randn = random.randint(1,10)
# settings to capture the photo
camera_port = 0
ramp_frames = 30
camera = cv2.VideoCapture(camera_port)
def get_image():
retval, im = camera.read()
return im
for i in range(ramp_frames):
temp = get_image()
# Take the photo
print("Taking image...")
# capture 150 photos
for i in range(0, 150):
# Sleep time of 0.01 seconds
time.sleep(0.01)
camera_capture = get_image()
# dir to save the file + file name
file = "D:/WorkArea/GitHub/tensorflow-for-poets-2/tf_files/Humans/" + str(human_me.HUMAN()) + '/' +"_image" + str(i) + ".jpg"
cv2.imwrite(file, camera_capture)
del(camera) # close the object
# print the name of the person
print(human_me.HUMAN())
## IMPORTANT
# training script with training steps set to 100
os.system("python -m scripts.retrain --bottleneck_dir=tf_files/bottlenecks --how_many_training_steps=100 --model_dir=tf_files/models/inception --output_graph=tf_files/retrained_graph.pb --output_labels=tf_files/retrained_labels.txt --image_dir=tf_files/Humans")
# test script is invovked to for a quick test.
test.testimg()