-
Notifications
You must be signed in to change notification settings - Fork 3
/
train.py
94 lines (68 loc) · 2.51 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
84
85
86
87
88
89
90
91
92
93
94
from clarifai.rest import ClarifaiApp
from clarifai.rest import Image as ClImage
from glob import glob
import os
def round():
image_set = create_image_set('/Users/mehty/Desktop/UofThacks/face-shape-recognition/round/', ['round-face'])
app.inputs.bulk_create_images(image_set)
def square():
image_set = create_image_set('Users/mehty/Desktop/UofThacks/face-shape-recognition/Square/', ['square-face'])
app.inputs.bulk_create_images(image_set)
def heart():
image_set = create_image_set('/Users/mehty/Desktop/UofThacks/face-shape-recognition/Heart/', ['heart-face'])
app.inputs.bulk_create_images(image_set)
def diamond():
image_set = create_image_set('/Users/mehty/Desktop/UofThacks/face-shape-recognition/Diamond/', ['diamond-face'])
app.inputs.bulk_create_images(image_set)
def long_face():
image_set = create_image_set('/Users/mehty/Desktop/UofThacks/face-shape-recognition/long/', ['long-face'])
app.inputs.bulk_create_images(image_set)
def oval():
image_set = create_image_set('/Users/mehty/Desktop/UofThacks/face-shape-recognition/oval/', ['oval-face'])
app.inputs.bulk_create_images(image_set)
def train_round():
model = app.models.create(model_id="face-shapes", concepts=['round-face'])
model.train()
def train_square():
model = app.models.create(model_id="face-shapes", concepts=['square-face'])
model.train()
def train_heart():
model = app.models.create(model_id="face-shapes", concepts=['heart-face'])
model.train()
def train_diamond():
model = app.models.create(model_id="face-shapes", concepts=['diamond-face'])
model.train()
def train_long():
model = app.models.create(model_id="face-shapes", concepts=['long-face'])
model.train()
def train_oval():
model = app.models.create(model_id="face-shapes", concepts=['oval-face'])
model.train()
def main():
app = ClarifaiApp()
model = app.models.get('face-shapes')
bytes = raw_input("base 64 encoded image bytes: ")
print model.predict_by_base64(bytes)['outputs'][0]['data']['concepts']
def create_image_set(img_path, concepts):
images = []
for file_path in glob(os.path.join(img_path, '*.jpg')):
print(file_path)
img = ClImage(filename=file_path, concepts=concepts)
images.append(img)
print images
if __name__ == '__main__':
main()
#if __name__ == '__round__':
# round()
#if __name__ == '__square__':
# square()
#if __name__ == '__h__':
# heart()
#if __name__ == '__diamond__':
# diamond()
#if __name__ == '__long_face__':
# long_face()
#if __name__ == '__oval__':
# oval()
if __name__ == '__train_square__':
train_square()