Skip to content

Commit b10abd1

Browse files
committed
wip #63 almost there
1 parent 0c35ae3 commit b10abd1

File tree

10 files changed

+86
-31
lines changed

10 files changed

+86
-31
lines changed

camera.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import logging
3030

3131
from cv import camera, streamer, image, blob
32-
from cnn_classifier import CNNClassifier
32+
33+
from cnn_manager import CNNManager
34+
3335
import config
3436

3537
MAX_IMAGE_AGE = 0.0
@@ -79,7 +81,9 @@ def __init__(self):
7981
self._photos.append({'name': filename})
8082
self.save_photo_metadata()
8183

82-
self._cnn_classifier = CNNClassifier("cnn_models/applekiwi_0_5_128.pb", "cnn_models/applekiwi_0_5_128.txt", "input", "final_result", 128, 128, 0.0, 255.0)
84+
cnn_model = config.Config.get().get("cnn_default_model", "")
85+
if cnn_model != "":
86+
self._cnn_classifier = CNNManager.get_instance().load_model(cnn_model)
8387

8488
super(Camera, self).__init__()
8589

cnn_classifier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import tensorflow as tf
2525

2626
class CNNClassifier:
27-
def __init__(self, model_file, label_file, input_layer="input", output_layer="final_output", input_height=128, input_width=128, input_mean=127.5, input_std=127.5):
27+
def __init__(self, model_file, label_file, input_layer="input", output_layer="final_result", input_height=128, input_width=128, input_mean=127.5, input_std=127.5):
2828
self._graph = self.load_graph(model_file)
2929
self._labels = self.load_labels(label_file)
3030
input_name = "import/" + input_layer

cnn_manager.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import threading
66

77
from cnn_train import CNNTrainer
8+
from cnn_classifier import CNNClassifier
89

910
MODEL_PATH = "./cnn_models"
1011
MODEL_TMP_PATH = "/tmp/images"
@@ -28,9 +29,8 @@ def __init__(self):
2829
f.close
2930
except IOError:
3031
self._models = {}
31-
f = open(MODEL_METADATA, "w")
32-
json.dump(self._models, f)
33-
f.close
32+
self._save_model_meta()
33+
3434
self._trainers = {}
3535

3636
def get_models(self):
@@ -39,10 +39,17 @@ def get_models(self):
3939
def get_model_status(self, model_name):
4040
return self._models[model_name]
4141

42+
def _save_model_meta(self):
43+
f = open(MODEL_METADATA, "w")
44+
json.dump(self._models, f)
45+
f.close
46+
4247
def delete_model(self, model_name):
4348
if self._models.get(model_name):
44-
os.remove(MODEL_PATH + "/" + model_name + ".*")
49+
os.remove(MODEL_PATH + "/" + model_name + ".pb")
50+
os.remove(MODEL_PATH + "/" + model_name + ".txt")
4551
del self._models[model_name]
52+
self._save_model_meta()
4653

4754
def train_new_model(self,
4855
model_name,
@@ -58,12 +65,22 @@ def train_new_model(self,
5865
self._trainers[model_name] = trainer
5966
#trainer.join()
6067

61-
def save_model(self, model_name, architecture):
68+
def save_model_status(self, model_name, architecture, status):
6269
model_info = architecture.split("_")
63-
self._models[model_name] = {"status": 1, "image_height": model_info[2], "image_width": model_info[2]}
64-
f = open(MODEL_METADATA, "w")
65-
json.dump(self._models, f)
66-
f.close()
70+
self._models[model_name] = {"status": status, "image_height": model_info[2], "image_width": model_info[2]}
71+
self._save_model_meta()
72+
73+
def wait_train_jobs(self):
74+
for t in self._trainers:
75+
t.join()
76+
77+
def load_model(self, model_name):
78+
model_info = self._models.get(model_name)
79+
if model_info:
80+
return CNNClassifier(model_file = MODEL_PATH + "/" + model_name + ".pb",
81+
label_file = MODEL_PATH + "/" + model_name + ".txt",
82+
input_height = int(model_info["image_height"]),
83+
input_width = int(model_info["image_width"]))
6784

6885
class TrainThread(threading.Thread):
6986

@@ -76,17 +93,18 @@ def __init__(self, manager, model_name, architecture, image_tags, photos_metadat
7693
self.photos_metadata = photos_metadata
7794
self.learning_rate = learning_rate
7895
self.training_steps = training_steps
79-
self.trainer = CNNTrainer(architecture)
96+
self.trainer = CNNTrainer(manager, architecture)
8097

8198
def update_train_status(self, model_name, status):
8299
model = self.manager._models.get(model_name)
83100
model["status"] = status
84101

85102
def run(self):
103+
self.manager.save_model_status(self.model_name, self.architecture, 0)
86104
image_dir = self.prepare_images()
87105
logging.info("retrain")
88106
self.trainer.retrain(image_dir, MODEL_PATH + "/" + self.model_name, self.training_steps, self.learning_rate)
89-
self.manager.save_model(self.model_name, self.architecture)
107+
self.manager.save_model_status(self.model_name, self.architecture, 1)
90108
self.clear_filesystem()
91109
logging.info("finish")
92110

cnn_train.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@
122122

123123

124124
class CNNTrainer:
125-
def __init__(self, architecture):
125+
def __init__(self, manager, architecture):
126+
self.manager = manager
126127
self.architecture=architecture
127128
self.intermediate_output_graphs_dir = "/tmp/intermediate_graph/"
128129
self.intermediate_store_frequency = 0
@@ -295,6 +296,8 @@ def retrain(self,
295296
intermediate_file_name)
296297
self.save_graph_to_file(sess, self.graph, intermediate_file_name, final_tensor_name)
297298

299+
self.manager.save_model_status(output_graph[output_graph.rfind("/")+1:], self.architecture, i / training_steps)
300+
298301
# We've completed all our training, so run a final test evaluation on
299302
# some new images we haven't used before.
300303
test_bottlenecks, test_ground_truth, test_filenames = (

coderbot.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"move_tr_speed": "80", "move_fw_elapse": "1", "camera_color_object_size_min": "4000", "camera_path_object_size_min": "4000", "load_at_start": "", "move_tr_elapse": "0.5", "sound_stop": "$shutdown.mp3", "show_control_move_commands": "true", "prog_level": "adv", "prog_scrollbars": "true", "move_fw_speed": "100", "camera_color_object_size_max": "160000", "sound_shutter": "$shutter.mp3", "show_page_prefs": "true", "cv_image_factor": "4", "ctrl_hud_image": "", "button_func": "none", "ctrl_fw_elapse": "-1", "ctrl_tr_elapse": "-1", "move_power_angle_2": "60", "move_power_angle_3": "60", "move_power_angle_1": "45", "move_motor_trim": "1", "show_page_program": "true", "sound_start": "$startup.mp3", "camera_exposure_mode": "auto", "ctrl_tr_speed": "80", "prog_move_mpu": "yes", "ctrl_fw_speed": "100", "camera_refresh_timeout": "0.1", "camera_jpeg_quality": "20", "prog_maxblocks": "-1", "move_motor_mode": "dc", "camera_path_object_size_max": "160000", "show_page_control": "true"}
1+
{"move_tr_speed": "80", "move_fw_elapse": "1", "camera_color_object_size_min": "4000", "camera_path_object_size_min": "4000", "load_at_start": "", "move_tr_elapse": "0.5", "sound_stop": "$shutdown.mp3", "show_control_move_commands": "true", "prog_level": "adv", "prog_scrollbars": "true", "move_fw_speed": "100", "camera_color_object_size_max": "160000", "sound_shutter": "$shutter.mp3", "show_page_prefs": "true", "cv_image_factor": "4", "ctrl_hud_image": "", "button_func": "none", "ctrl_fw_elapse": "-1", "ctrl_tr_elapse": "-1", "move_power_angle_2": "60", "move_power_angle_3": "60", "move_power_angle_1": "45", "move_motor_trim": "1", "cnn_default_model": "apple_kiwi_fast", "show_page_program": "true", "sound_start": "$startup.mp3", "camera_exposure_mode": "auto", "ctrl_tr_speed": "80", "prog_move_mpu": "yes", "ctrl_fw_speed": "100", "camera_refresh_timeout": "0.1", "camera_jpeg_quality": "20", "prog_maxblocks": "-1", "move_motor_mode": "dc", "camera_path_object_size_max": "160000", "show_page_control": "true"}

main.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,32 +290,32 @@ def handle_program_status():
290290
@app.route("/cnnmodels", methods=["GET"])
291291
def handle_cnn_models_list():
292292
logging.info("cnn_models_list")
293-
return json.dumps(app.cnn.get_models())
293+
return json.dumps(cnn.get_models())
294294

295295
@app.route("/cnnmodels", methods=["POST"])
296296
def handle_cnn_models_new():
297297
logging.info("cnn_models_new")
298298
data = json.loads(request.get_data())
299-
app.cnn.train_new_model(model_name=data["model_name"],
299+
cnn.train_new_model(model_name=data["model_name"],
300300
architecture=data["architecture"],
301301
image_tags=data["image_tags"],
302302
photos_meta=cam.get_photo_list(),
303303
training_steps=data["training_steps"],
304-
learning_rate=data["training_rate"])
304+
learning_rate=data["learning_rate"])
305305

306306
return json.dumps({"name": data["model_name"], "status": 0})
307307

308308
@app.route("/cnnmodels/<model_name>", methods=["GET"])
309309
def handle_cnn_models_status(model_name):
310310
logging.info("cnn_models_status")
311-
model_status = app.cnn.get_model(model_name=model_name)
311+
model_status = cnn.get_model(model_name=model_name)
312312

313313
return json.dumps(model_status)
314314

315315
@app.route("/cnnmodels/<model_name>", methods=["DELETE"])
316316
def handle_cnn_models_delete(model_name):
317317
logging.info("cnn_models_delete")
318-
model_status = app.cnn.delete_model(model_name=model_name)
318+
model_status = cnn.delete_model(model_name=model_name)
319319

320320
return json.dumps(model_status)
321321

@@ -357,8 +357,15 @@ def run_server():
357357
logging.error("Camera not present")
358358

359359
cnn = CNNManager.get_instance()
360-
app.cnn = cnn
361-
360+
"""
361+
cnn.train_new_model(model_name="test3",
362+
architecture="mobilenet_0.25_128",
363+
image_tags=["apple", "kiwi", "other"],
364+
photos_meta=cam.get_photo_list(),
365+
training_steps=10,
366+
learning_rate=0.1)
367+
logging.info("trained")
368+
"""
362369
if app.bot_config.get('load_at_start') and len(app.bot_config.get('load_at_start')):
363370
app.prog = app.prog_engine.load(app.bot_config.get('load_at_start'))
364371
app.prog.execute()

photos/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"tag": "", "name": "DSC110.jpg"}, {"tag": "other", "name": "DSC19.jpg"}, {"tag": "other", "name": "DSC111.jpg"}, {"tag": "kiwi", "name": "DSC94.jpg"}, {"tag": "other", "name": "DSC113.jpg"}, {"tag": "other", "name": "DSC118.jpg"}, {"tag": "apple", "name": "DSC60.jpg"}, {"tag": "other", "name": "DSC112.jpg"}, {"tag": "apple", "name": "DSC38.jpg"}, {"tag": "kiwi", "name": "DSC73.jpg"}, {"tag": "apple", "name": "DSC49.jpg"}, {"tag": "other", "name": "DSC24.jpg"}, {"tag": "kiwi", "name": "DSC74.jpg"}, {"tag": "kiwi", "name": "DSC96.jpg"}, {"tag": "kiwi", "name": "DSC97.jpg"}, {"tag": "apple", "name": "DSC48.jpg"}, {"tag": "other", "name": "DSC121.jpg"}, {"tag": "other", "name": "DSC15.jpg"}, {"tag": "other", "name": "DSC3.jpg"}, {"tag": "other", "name": "DSC9.jpg"}, {"tag": "other", "name": "DSC115.jpg"}, {"tag": "apple", "name": "DSC30.jpg"}, {"tag": "other", "name": "DSC22.jpg"}, {"tag": "other", "name": "DSC103.jpg"}, {"tag": "kiwi", "name": "DSC86.jpg"}, {"tag": "apple", "name": "DSC35.jpg"}, {"tag": "apple", "name": "DSC34.jpg"}, {"tag": "other", "name": "DSC100.jpg"}, {"tag": "apple", "name": "DSC29.jpg"}, {"tag": "apple", "name": "DSC61.jpg"}, {"tag": "kiwi", "name": "DSC77.jpg"}, {"tag": "kiwi", "name": "DSC95.jpg"}, {"tag": "kiwi", "name": "DSC93.jpg"}, {"tag": "kiwi", "name": "DSC89.jpg"}, {"tag": "kiwi", "name": "DSC62.jpg"}, {"name": "DSC10.jpg"}, {"tag": "other", "name": "DSC108.jpg"}, {"tag": "kiwi", "name": "DSC80.jpg"}, {"tag": "apple", "name": "DSC65.jpg"}, {"tag": "other", "name": "DSC123.jpg"}, {"tag": "apple", "name": "DSC55.jpg"}, {"tag": "apple", "name": "DSC50.jpg"}, {"name": "DSC4.jpg"}, {"tag": "kiwi", "name": "DSC75.jpg"}, {"tag": "other", "name": "DSC8.jpg"}, {"tag": "kiwi", "name": "DSC85.jpg"}, {"tag": "other", "name": "DSC104.jpg"}, {"tag": "kiwi", "name": "DSC88.jpg"}, {"tag": "apple", "name": "DSC59.jpg"}, {"tag": "apple", "name": "DSC41.jpg"}, {"tag": "other", "name": "DSC13.jpg"}, {"tag": "apple", "name": "DSC40.jpg"}, {"tag": "apple", "name": "DSC37.jpg"}, {"tag": "kiwi", "name": "DSC87.jpg"}, {"tag": "other", "name": "DSC14.jpg"}, {"tag": "apple", "name": "DSC64.jpg"}, {"tag": "other", "name": "DSC12.jpg"}, {"tag": "apple", "name": "DSC57.jpg"}, {"tag": "kiwi", "name": "DSC83.jpg"}, {"tag": "kiwi", "name": "DSC70.jpg"}, {"name": "DSC21.jpg"}, {"name": "DSC98.jpg"}, {"name": "DSC23.jpg"}, {"name": "DSC120.jpg"}, {"name": "DSC99.jpg"}, {"tag": "apple", "name": "DSC46.jpg"}, {"name": "DSC107.jpg"}, {"tag": "apple", "name": "DSC66.jpg"}, {"tag": "apple", "name": "DSC31.jpg"}, {"tag": "apple", "name": "DSC36.jpg"}, {"tag": "apple", "name": "DSC47.jpg"}, {"name": "DSC11.jpg"}, {"name": "DSC76.jpg"}, {"name": "DSC82.jpg"}, {"name": "DSC106.jpg"}, {"name": "DSC56.jpg"}, {"name": "DSC67.jpg"}, {"name": "DSC42.jpg"}, {"name": "DSC45.jpg"}, {"name": "DSC54.jpg"}, {"name": "DSC68.jpg"}, {"name": "DSC5.jpg"}, {"name": "DSC25.jpg"}, {"name": "DSC44.jpg"}, {"name": "DSC81.jpg"}, {"name": "DSC27.jpg"}, {"name": "DSC124.jpg"}, {"name": "DSC114.jpg"}, {"name": "DSC69.jpg"}, {"name": "DSC72.jpg"}, {"name": "DSC18.jpg"}, {"name": "DSC20.jpg"}, {"name": "DSC63.jpg"}, {"name": "DSC52.jpg"}, {"name": "DSC7.jpg"}, {"name": "DSC84.jpg"}, {"name": "DSC53.jpg"}, {"name": "DSC102.jpg"}, {"name": "DSC90.jpg"}, {"name": "DSC109.jpg"}, {"name": "DSC119.jpg"}, {"name": "DSC6.jpg"}, {"name": "DSC33.jpg"}, {"name": "DSC32.jpg"}, {"name": "DSC71.jpg"}, {"name": "DSC116.jpg"}, {"name": "DSC51.jpg"}, {"name": "DSC101.jpg"}, {"name": "DSC79.jpg"}, {"name": "DSC16.jpg"}, {"name": "DSC28.jpg"}, {"name": "DSC26.jpg"}, {"name": "DSC91.jpg"}, {"name": "DSC43.jpg"}, {"name": "DSC125.jpg"}, {"name": "DSC92.jpg"}, {"name": "DSC117.jpg"}, {"name": "DSC39.jpg"}, {"name": "DSC126.jpg"}, {"name": "DSC17.jpg"}, {"name": "DSC78.jpg"}, {"name": "DSC127.jpg"}, {"name": "DSC122.jpg"}, {"name": "DSC58.jpg"}]
1+
[{"tag": "", "name": "DSC110.jpg"}, {"tag": "other", "name": "DSC19.jpg"}, {"tag": "other", "name": "DSC111.jpg"}, {"tag": "kiwi", "name": "DSC94.jpg"}, {"tag": "other", "name": "DSC113.jpg"}, {"tag": "other", "name": "DSC118.jpg"}, {"tag": "apple", "name": "DSC60.jpg"}, {"tag": "other", "name": "DSC112.jpg"}, {"tag": "apple", "name": "DSC38.jpg"}, {"tag": "kiwi", "name": "DSC73.jpg"}, {"tag": "apple", "name": "DSC49.jpg"}, {"tag": "other", "name": "DSC24.jpg"}, {"tag": "kiwi", "name": "DSC74.jpg"}, {"tag": "kiwi", "name": "DSC96.jpg"}, {"tag": "kiwi", "name": "DSC97.jpg"}, {"tag": "apple", "name": "DSC48.jpg"}, {"tag": "other", "name": "DSC121.jpg"}, {"tag": "other", "name": "DSC15.jpg"}, {"tag": "other", "name": "DSC3.jpg"}, {"tag": "other", "name": "DSC9.jpg"}, {"tag": "other", "name": "DSC115.jpg"}, {"tag": "apple", "name": "DSC30.jpg"}, {"tag": "other", "name": "DSC22.jpg"}, {"tag": "other", "name": "DSC103.jpg"}, {"tag": "kiwi", "name": "DSC86.jpg"}, {"tag": "apple", "name": "DSC35.jpg"}, {"tag": "apple", "name": "DSC34.jpg"}, {"tag": "other", "name": "DSC100.jpg"}, {"tag": "apple", "name": "DSC29.jpg"}, {"tag": "apple", "name": "DSC61.jpg"}, {"tag": "kiwi", "name": "DSC77.jpg"}, {"tag": "kiwi", "name": "DSC95.jpg"}, {"tag": "kiwi", "name": "DSC93.jpg"}, {"tag": "kiwi", "name": "DSC89.jpg"}, {"tag": "kiwi", "name": "DSC62.jpg"}, {"name": "DSC10.jpg"}, {"tag": "other", "name": "DSC108.jpg"}, {"tag": "kiwi", "name": "DSC80.jpg"}, {"tag": "apple", "name": "DSC65.jpg"}, {"tag": "other", "name": "DSC123.jpg"}, {"tag": "apple", "name": "DSC55.jpg"}, {"tag": "apple", "name": "DSC50.jpg"}, {"name": "DSC4.jpg"}, {"tag": "kiwi", "name": "DSC75.jpg"}, {"tag": "other", "name": "DSC8.jpg"}, {"tag": "kiwi", "name": "DSC85.jpg"}, {"tag": "other", "name": "DSC104.jpg"}, {"tag": "kiwi", "name": "DSC88.jpg"}, {"tag": "apple", "name": "DSC59.jpg"}, {"tag": "apple", "name": "DSC41.jpg"}, {"tag": "other", "name": "DSC13.jpg"}, {"tag": "apple", "name": "DSC40.jpg"}, {"tag": "apple", "name": "DSC37.jpg"}, {"tag": "kiwi", "name": "DSC87.jpg"}, {"tag": "other", "name": "DSC14.jpg"}, {"tag": "apple", "name": "DSC64.jpg"}, {"tag": "other", "name": "DSC12.jpg"}, {"tag": "apple", "name": "DSC57.jpg"}, {"tag": "kiwi", "name": "DSC83.jpg"}, {"tag": "kiwi", "name": "DSC70.jpg"}, {"name": "DSC21.jpg"}, {"name": "DSC98.jpg"}, {"name": "DSC23.jpg"}, {"name": "DSC120.jpg"}, {"name": "DSC99.jpg"}, {"tag": "apple", "name": "DSC46.jpg"}, {"name": "DSC107.jpg"}, {"tag": "apple", "name": "DSC66.jpg"}, {"tag": "apple", "name": "DSC31.jpg"}, {"tag": "apple", "name": "DSC36.jpg"}, {"tag": "apple", "name": "DSC47.jpg"}, {"name": "DSC11.jpg"}, {"name": "DSC76.jpg"}, {"name": "DSC82.jpg"}, {"name": "DSC106.jpg"}, {"name": "DSC56.jpg"}, {"name": "DSC67.jpg"}, {"name": "DSC42.jpg"}, {"name": "DSC45.jpg"}, {"name": "DSC54.jpg"}, {"name": "DSC68.jpg"}, {"name": "DSC5.jpg"}, {"name": "DSC25.jpg"}, {"name": "DSC44.jpg"}, {"name": "DSC81.jpg"}, {"name": "DSC27.jpg"}, {"name": "DSC124.jpg"}, {"name": "DSC114.jpg"}, {"name": "DSC69.jpg"}, {"tag": "kiwi", "name": "DSC72.jpg"}, {"name": "DSC18.jpg"}, {"name": "DSC20.jpg"}, {"name": "DSC63.jpg"}, {"name": "DSC52.jpg"}, {"name": "DSC7.jpg"}, {"tag": "kiwi", "name": "DSC84.jpg"}, {"name": "DSC53.jpg"}, {"name": "DSC102.jpg"}, {"tag": "kiwi", "name": "DSC90.jpg"}, {"name": "DSC109.jpg"}, {"tag": "other", "name": "DSC119.jpg"}, {"name": "DSC6.jpg"}, {"tag": "apple", "name": "DSC33.jpg"}, {"tag": "apple", "name": "DSC32.jpg"}, {"tag": "kiwi", "name": "DSC71.jpg"}, {"tag": "other", "name": "DSC116.jpg"}, {"tag": "apple", "name": "DSC51.jpg"}, {"tag": "other", "name": "DSC101.jpg"}, {"tag": "kiwi", "name": "DSC79.jpg"}, {"tag": "other", "name": "DSC16.jpg"}, {"tag": "other", "name": "DSC28.jpg"}, {"tag": "apple", "name": "DSC26.jpg"}, {"tag": "kiwi", "name": "DSC91.jpg"}, {"tag": "apple", "name": "DSC43.jpg"}, {"tag": "other", "name": "DSC125.jpg"}, {"tag": "kiwi", "name": "DSC92.jpg"}, {"tag": "other", "name": "DSC117.jpg"}, {"tag": "apple", "name": "DSC39.jpg"}, {"tag": "other", "name": "DSC126.jpg"}, {"tag": "other", "name": "DSC17.jpg"}, {"tag": "kiwi", "name": "DSC78.jpg"}, {"tag": "other", "name": "DSC127.jpg"}, {"tag": "other", "name": "DSC122.jpg"}, {"tag": "apple", "name": "DSC58.jpg"}]

static/js/.control.js.swp

28 KB
Binary file not shown.

static/js/control.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,25 +136,46 @@ $(document).on( "pagecreate", '#page-preferences', function( event ) {
136136
});
137137
return false;
138138
});
139+
$.get(url='/cnnmodels', success= function(data) {
140+
$('#i_cnn_default_model').empty();
141+
$('#i_cnn_default_model').append('<option></option>');
142+
for(m in data) {
143+
if(Math.trunc(parseInt(data[m].status))==1){
144+
$('#i_cnn_default_model').append('<option value="'+m+'">'+m+'</option>');
145+
}
146+
}
147+
$('#i_cnn_default_model').selectmenu("refresh");
148+
149+
}, dataType="json");
139150
$( "#popup-cnn-models" ).bind({
140151
popupbeforeposition: function(event, ui) {
141152
$.get(url='/cnnmodels', success= function(data) {
142153
$('#cnn-model-list').empty();
143154
for(m in data) {
144-
console.log(m);
145-
$('#cnn-model-list').append('<li data-icon="delete"><a href="#">'+m+' [' + data[m].status +']</a></li>');
155+
$('#cnn-model-list').append('<li data-icon="delete"><a href="#" data-name="'+m+'" class="b_cnn_model_delete">'+m+' [' + Math.trunc(parseFloat(data[m].status) * 100) +'%]</a></li>');
146156
}
147157
$('#cnn-model-list').listview('refresh');
158+
$('.b_cnn_model_delete').on('click', function(event, ui) {
159+
var model_name = $(event.target).attr("data-name");
160+
if(confirm("Delete model " + model_name + "?")) {
161+
$.ajax({url:'/cnnmodels/'+model_name, method: "DELETE", success: function(data) {
162+
console.log("model_name: " + model_name);
163+
$('#cnn-model-list a[data-name="' + model_name + '"]').parent().remove();
164+
$('#cnn-model-list').listview('refresh');
165+
}
166+
});
167+
}
168+
});
148169
}, dataType='json')
149170
}
150171
});
151172
$( "#f_cnn_train" ).submit(function (){
152173
var form = $(event.target);
153174
var data = {architecture: form.find("#i_cnn_model_arch").val(),
154175
model_name: form.find("#i_cnn_model_name").val(),
155-
training_steps: form.find("#i_cnn_train_steps").val(),
156-
training_rate: form.find("#i_cnn_learn_rate").val(),
157-
image_tags: ["apple", "kiwi", "other"]};
176+
training_steps: parseInt(form.find("#i_cnn_train_steps").val()),
177+
learning_rate: parseFloat(form.find("#i_cnn_learn_rate").val()),
178+
image_tags: form.find("#i_cnn_image_tags").val().split(",")};
158179
console.log(data);
159180
$.post(url='/cnnmodels', data=JSON.stringify(data), success=function(data) {
160181
alert("training...");

0 commit comments

Comments
 (0)