From e898a4a990f24bb04c38073b6d9159a32aabe55d Mon Sep 17 00:00:00 2001 From: Caleb Robinson Date: Wed, 15 Jul 2020 22:53:38 +0000 Subject: [PATCH] Two big changes: - Fixed everything about new label class counting - Fully converted corrections into point corrections --- server.py | 6 ++-- web_tool/Models.py | 1 + web_tool/ServerModelsKerasDense.py | 16 ++++----- web_tool/ServerModelsTorch.py | 4 +-- web_tool/index.html | 56 +++++++++++------------------- web_tool/js/handlers.js | 4 +-- web_tool/js/utils.js | 5 ++- web_tool/models.json | 16 ++++----- 8 files changed, 46 insertions(+), 62 deletions(-) diff --git a/server.py b/server.py index 07d23a8..0a63979 100644 --- a/server.py +++ b/server.py @@ -181,7 +181,7 @@ def record_correction(): SESSION_HANDLER.get_session(bottle.request.session.id).add_entry(data) # record this interaction # - lat, lon = data["point"]["x"], data["point"]["y"] + lon, lat = data["point"]["x"], data["point"]["y"] class_list = data["classes"] name_list = [item["name"] for item in class_list] color_list = [item["color"] for item in class_list] @@ -191,11 +191,11 @@ def record_correction(): # load the current predicted patches crs and transform data_crs, data_transform = SESSION_HANDLER.get_session(bottle.request.session.id).current_transform - x, y = fiona.transform.transform(origin_crs, data_crs.to_dict(), [lon], [lat]) + x, y = fiona.transform.transform(origin_crs, data_crs.to_string(), [lon], [lat]) x = x[0] y = y[0] - dst_row, dst_col = (~data_transform) * (y, x) + dst_col, dst_row = (~data_transform) * (x,y) dst_row = int(np.floor(dst_row)) dst_col = int(np.floor(dst_col)) diff --git a/web_tool/Models.py b/web_tool/Models.py index 59d53ff..d740a74 100644 --- a/web_tool/Models.py +++ b/web_tool/Models.py @@ -12,6 +12,7 @@ def _load_model(model): return False return { "fn": model["model"]["fn"], + "type": model["model"]["type"], "fine_tune_layer": model["model"]["fineTuneLayer"] } diff --git a/web_tool/ServerModelsKerasDense.py b/web_tool/ServerModelsKerasDense.py index e2b41be..e020f71 100644 --- a/web_tool/ServerModelsKerasDense.py +++ b/web_tool/ServerModelsKerasDense.py @@ -178,8 +178,11 @@ class KerasDenseFineTune(BackendModel): return output def retrain(self, **kwargs): - x_train = np.concatenate(self.augment_x_train, axis=0) - y_train = np.concatenate(self.augment_y_train, axis=0) + x_train = np.array(self.augment_x_train) + y_train = np.array(self.augment_y_train) + + print(x_train.shape) + print(y_train.shape) vals, counts = np.unique(y_train, return_counts=True) @@ -197,12 +200,9 @@ class KerasDenseFineTune(BackendModel): return success, message - def add_sample(self, tdst_row, bdst_row, tdst_col, bdst_col, class_idx): - x_features = self.current_features[tdst_row:bdst_row+1, tdst_col:bdst_col+1, :].copy().reshape(-1, self.current_features.shape[2]) - y_samples = np.zeros((x_features.shape[0]), dtype=np.uint8) - y_samples[:] = class_idx - self.augment_x_train.append(x_features) - self.augment_y_train.append(y_samples) + def add_sample_point(self, row, col, class_idx): + self.augment_x_train.append(self.current_features[row, col, :].copy()) + self.augment_y_train.append(class_idx) self.undo_stack.append("sample") def undo(self): diff --git a/web_tool/ServerModelsTorch.py b/web_tool/ServerModelsTorch.py index f8ae3af..0ab2574 100644 --- a/web_tool/ServerModelsTorch.py +++ b/web_tool/ServerModelsTorch.py @@ -39,9 +39,7 @@ class TorchFineTuning(BackendModel): def __init__(self, model_fn, gpuid, fine_tune_layer): self.model_fn = model_fn - self.device = torch.device("cuda:1" if torch.cuda.is_available() else "cpu") - - print("Using device", self.device) + self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") self.output_channels = 14 self.output_features = 64 diff --git a/web_tool/index.html b/web_tool/index.html index e1ed387..bbbec28 100644 --- a/web_tool/index.html +++ b/web_tool/index.html @@ -59,24 +59,7 @@

Correction type:

-
- -
+
@@ -220,18 +203,20 @@ for(var i=0;i"); - var newLabel = $(""); + var newLabel = $(" \ + \ + "); var newPicker = document.createElement('button'); newPicker.classList.add("circle"); newPicker.classList.add("jscolor"); - newPicker.setAttribute("data-class-name", "Class "+newClassIdx); + newPicker.setAttribute("data-class-label", newClassName); + newPicker.setAttribute("data-class-idx", newClassIdx); var output = new jscolor(newPicker, { valueElement: null, value: newColor.substr(1), @@ -248,7 +233,7 @@ $("#classList").append(newClassElement); CLASSES.push({ - "name": "Class " + newClassIdx, + "name": newClassName, "color": newColor, "count": 0 }); @@ -306,7 +291,7 @@ //---------------------------------------------------------------------- addCustomLogoControl(); addZoomControls(); - addDrawControls(); + //addDrawControls(); var basemapPickerControl = addBasemapPickerControl(gBasemaps); var basemapPickerControlContainer = basemapPickerControl.getContainer(); @@ -381,15 +366,19 @@ $("#btnNewClass").click(function(){ var newClassIdx = CLASSES.length; + var newClassName = "Class " + (newClassIdx + 1); var newColor = getRandomColor(); var newClassElement = $("
"); - var newLabel = $(""); + var newLabel = $(" \ + \ + "); var newPicker = document.createElement('button'); newPicker.classList.add("circle"); newPicker.classList.add("jscolor"); - newPicker.setAttribute("data-class-name", "Class "+newClassIdx); + newPicker.setAttribute("data-class-label", newClassName); + newPicker.setAttribute("data-class-idx", newClassIdx); var output = new jscolor(newPicker, { valueElement: null, value: newColor.substr(1), @@ -406,37 +395,34 @@ $("#classList").append(newClassElement); CLASSES.push({ - "name": "Class " + newClassIdx, + "name": newClassName, "color": newColor, "count": 0 }); - }); //---------------------------------------------------------------------- // Setup radio button change detection //---------------------------------------------------------------------- - $(document).on('change', '.radNewClass', function(){ + $(document).on('change', '.radClasses', function(){ $('.radio label').removeClass("selected"); $(this).parent().addClass("selected"); gSelectedClassIdx = findClassByName(this.value); - console.debug(this.value + " " + gSelectedClassIdx); }); $(document).on('click', '.classNameEdit', function(){ var oldName = $(this).siblings(".className").html(); var newName = prompt("New label name for '"+oldName+"'"); $(this).siblings(".className").html(newName); - $(this).siblings(".radNewClass").val(newName); + $(this).siblings(".radClasses").val(newName); $(this).parent().siblings(".jscolor").attr("data-class-name", newName); - var classIdx = findClassByName(oldName) + var classIdx = findClassByName(oldName); + console.debug(classIdx); CLASSES[classIdx]["name"] = newName; - - }); //---------------------------------------------------------------------- diff --git a/web_tool/js/handlers.js b/web_tool/js/handlers.js index 4f79a0c..d4f5be5 100644 --- a/web_tool/js/handlers.js +++ b/web_tool/js/handlers.js @@ -8,7 +8,7 @@ var addInferenceMouseHandlers = function(){ if(!gShiftKeyDown){ curSelPoly = getPolyAround(e.latlng, 1, false); }else{ - curSelPoly = getPolyAround(e.latlng, INFERENCE_WINDOW_SIZE, true); + curSelPoly = getPolyAround(e.latlng, INFERENCE_WINDOW_SIZE, true, true); } if(gSelectionBox === null){ @@ -35,7 +35,7 @@ var addInferenceMouseHandlers = function(){ var curSelPoly = null; if(gShiftKeyDown){ // Run the inference path - curSelPoly = getPolyAround(e.latlng, INFERENCE_WINDOW_SIZE, true); + curSelPoly = getPolyAround(e.latlng, INFERENCE_WINDOW_SIZE, true, true); if(gCurrentSelection === null){ // This condition creates the red selection box on the first click gCurrentSelection = L.polygon(curSelPoly, { color: "#ff0000", diff --git a/web_tool/js/utils.js b/web_tool/js/utils.js index 27c418c..cfe4f32 100644 --- a/web_tool/js/utils.js +++ b/web_tool/js/utils.js @@ -12,12 +12,11 @@ var findClassByIdx = function(idx){ } var renderClassCount = function(name, count){ - $(".radNewClass[value='"+name+"']").siblings(".classCounts").html(count); + $(".radClasses[value='"+name+"']").siblings(".classCounts").html(count); } var updateClassColor = function(obj){ - var className = $(obj.targetElement).attr("data-class-name"); - var classIdx = findClassByName(className); + var classIdx = $(obj.targetElement).attr("data-class-idx"); CLASSES[classIdx]["color"] = '#' + obj; }; diff --git a/web_tool/models.json b/web_tool/models.json index 3092855..880bbed 100644 --- a/web_tool/models.json +++ b/web_tool/models.json @@ -11,10 +11,10 @@ "fn": "data/models/sentinel_demo_model.h5" }, "classes":[ - {"label": "Water", "color": "#0000FF"}, - {"label": "Tree Canopy", "color": "#008000"}, - {"label": "Field", "color": "#80FF80"}, - {"label": "Built", "color": "#806060"} + {"name": "Water", "color": "#0000FF"}, + {"name": "Tree Canopy", "color": "#008000"}, + {"name": "Field", "color": "#80FF80"}, + {"name": "Built", "color": "#806060"} ] }, @@ -30,10 +30,10 @@ "fn": "data/models/naip_demo_model.h5" }, "classes":[ - {"label": "Water", "color": "#0000FF"}, - {"label": "Tree Canopy", "color": "#008000"}, - {"label": "Field", "color": "#80FF80"}, - {"label": "Built", "color": "#806060"} + {"name": "Water", "color": "#0000FF"}, + {"name": "Tree Canopy", "color": "#008000"}, + {"name": "Field", "color": "#80FF80"}, + {"name": "Built", "color": "#806060"} ] } }