-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
40 lines (27 loc) · 926 Bytes
/
Copy pathrun.py
File metadata and controls
40 lines (27 loc) · 926 Bytes
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
from model import Spinenet
from dataloader import DataLoader, get_Idx
from util import get_image
from params import Parameter
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
#create model
params = Parameter().get_args()
sp = Spinenet(params)
#training
if params.train:
dl = DataLoader(params)
batch_data = dl.get_train()
val_data = dl.get_val()
history = sp.model.fit(batch_data, epochs=params.epochs, validation_data=val_data)
sp.model.save(params.model_path)
#TODO Logging
else:
img = get_image('test_pics/dude_standing.jpg', before=False, after=False)
res = sp.model.predict(img)[0]
idx = np.argmax(res)
print(f'{get_Idx()[idx]} with {res[idx] * 100}')
if params.convert:
converter = tf.lite.TFLiteConverter.from_keras_model(sp.model)
tflite_model = converter.convert()
open(params.model_path + ".tflite", "wb").write(tflite_model)