Commit 365f0bf0 authored by Diego André Sant'Ana's avatar Diego André Sant'Ana 🤞
Browse files

fix problems in load files and load model with keras

parent 9e4ef8cc
......@@ -198,12 +198,11 @@ class CNNKeras(Classifier):
predict_directory=File.make_path(dataset, test_dir)
CLASS_NAMES = np.loadtxt(self.labels_file.value, str)
# Create a Keras class
# Create a Keras class
if not os.path.exists(File.make_path(predict_directory, "png")):
os.makedirs(File.make_path(predict_directory, "png"))
for file in os.listdir(predict_directory):
print(File.make_path(predict_directory, file))
#print(File.make_path(predict_directory, file))
if os.path.splitext(file)[-1] == ".tif":
try:
img = Image.open(File.make_path(predict_directory, file))
......@@ -216,7 +215,7 @@ class CNNKeras(Classifier):
else:
print(File.make_path(predict_directory, file))
#os.symlink(File.make_path(predict_directory, file),File.make_path(predict_directory, 'png', file))
print("Classes load from file examples/labels.txt")
print(CLASS_NAMES)
try:
......@@ -227,11 +226,7 @@ class CNNKeras(Classifier):
self.model = load_model(self.weight_path)
#path_classes = self.weight_path.replace( "_model.h5", "_classes.npy")
print("Load Model H5:"+self.weight_path)
#np_load_old = np.load
#modify the default parameters of np.load
#np.load = lambda *a,**k: np_load_old(*a, allow_pickle=True, **k)
#CLASS_NAMES = np.load(path_classes).item().keys()
except Exception as e:
raise IException("Can't load the model in " +
str(e))
......@@ -250,21 +245,11 @@ class CNNKeras(Classifier):
classify_generator, classify_generator.samples, verbose=2)
one_hot_output=np.argmax(output_classification, axis=1)
print(len(one_hot_output))
print(one_hot_output)
#output_classification = self.model.predict_generator(classify_generator)
#one_hot_output = np.argmax(output_classification, axis=1)
#one_hot_output = one_hot_output.tolist()
classes=[]
for index in range(0, len(one_hot_output)):
#print(index)
classes.append(CLASS_NAMES[one_hot_output[index]])
#print(len(classes))
return classes
def train(self, dataset, training_data, force=False):
......
......@@ -26,7 +26,7 @@ else:
self.Menu=Menu
self.Image=Image
self.Log=Log
self.Pop=Pop
self.Popup=Pop
self.CustomGrid=CustomGrid
self.SelectDialog=SelectDialog
self.ChooseOneDialog=ChooseOneDialog
......@@ -36,7 +36,7 @@ else:
tk_local.Menu=tk_menu.Menu
tk_local.Image=tk_canvas.Image
tk_local.Log=tk_logger.Log
tk_local.Pop=tk_popup.Popup
tk_local.Popup=tk_popup.Popup
tk_local.CustomGrid=tk_customframe.CustomGrid
tk_local.SelectDialog=tk_customdialog.SelectDialog
tk_local.ChooseOneDialog=tk_customdialog.ChooseOneDialog
......
......@@ -558,7 +558,7 @@ class Act(object):
self._gt_segments = [None]*(max(list_segments)+1)
# New and optimized classification
tmp = "tmp"
tmp = ".tmp"
File.remove_dir(File.make_path(self.dataset, tmp))
self.tk.append_log("Generating test images... (%0.3f seconds)", (TimeUtils.get_time() - start_time))
......@@ -618,7 +618,7 @@ class Act(object):
len_classes = sum([len_segments[idx] for idx in idx_segment])
popup_info += "%-16s%-16s%0.2f%%\n" % (cl["name"].value, str(len_classes), (len_classes*100.0)/len_total)
print(popup_info)
self.tk.refresh_image(self._image)
self.tk.popup(popup_info)
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment