From 3425ac6cf368b8ad497349169ade723101b96e88 Mon Sep 17 00:00:00 2001 From: Supun Nakandala Date: Fri, 29 Mar 2019 23:10:13 -0700 Subject: [PATCH] everything except time estimation working for the SysML demo --- code-release/core/python/inception3.py | 4 ++ code-release/core/python/resnet18.py | 4 ++ code-release/ui/krypton_ui/krypton/views.py | 14 +++-- .../krypton_ui/templates/index.html | 63 ++++++++++++------- 4 files changed, 58 insertions(+), 27 deletions(-) diff --git a/code-release/core/python/inception3.py b/code-release/core/python/inception3.py index f0a62ad..da1f186 100644 --- a/code-release/core/python/inception3.py +++ b/code-release/core/python/inception3.py @@ -585,6 +585,10 @@ def __initialize_weights(self, gpu): weights_data = load_dict_from_hdf5(dir_path + "/oct_inception3_ptch.h5", gpu) self.fc.weight.data = weights_data['482.fc.weight'] self.fc.bias.data = weights_data['483.fc.bias'] + if self.dataset == 'chest': + weights_data = load_dict_from_hdf5(dir_path + "/chest_inception3_ptch.h5", gpu) + self.fc.weight.data = weights_data['482.fc.weight'] + self.fc.bias.data = weights_data['483.fc.bias'] def __get_tensor(self, name, batch_size, channels, p_height, p_width, k_size, stride, in_size, out_size, truncate=True): diff --git a/code-release/core/python/resnet18.py b/code-release/core/python/resnet18.py index 0ceede0..5074d93 100644 --- a/code-release/core/python/resnet18.py +++ b/code-release/core/python/resnet18.py @@ -894,6 +894,10 @@ def __initialize_weights(self, gpu): weights_data = load_dict_from_hdf5(dir_path + "/oct_resnet18_ptch.h5", gpu) self.fc.weight.data = weights_data['fc:w'] self.fc.bias.data = weights_data['fc:b'] + elif self.dataset == 'chest': + weights_data = load_dict_from_hdf5(dir_path + "/chest_resnet18_ptch.h5", gpu) + self.fc.weight.data = weights_data['fc:w'] + self.fc.bias.data = weights_data['fc:b'] if __name__ == '__main__': diff --git a/code-release/ui/krypton_ui/krypton/views.py b/code-release/ui/krypton_ui/krypton/views.py index 27e1075..7e9cc44 100644 --- a/code-release/ui/krypton_ui/krypton/views.py +++ b/code-release/ui/krypton_ui/krypton/views.py @@ -21,7 +21,7 @@ import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt - +import numpy as np import torch, gc from commons import inc_inference, show_heatmap, full_inference_e2e from imagenet_classes import class_names @@ -139,9 +139,9 @@ def selectedRegion(request): heatmap, prob, label = inc_inference(dataset, model_class, curr_path, patch_size=patch_size, stride=stride_size, beta=1.0, x_size=299, y_size=299, image_size=299, gpu=True, c=c) elif mode == "approximate": if model_class != Inception3: - heatmap, prob, label = inc_inference(dataset, model_class, curr_path, patch_size=patch_size, stride=stride_size, beta=0.55, x_size=224, y_size=224, image_size=224, gpu=True, c=c) + heatmap, prob, label = inc_inference(dataset, model_class, curr_path, patch_size=patch_size, stride=stride_size, beta=0.5, x_size=224, y_size=224, image_size=224, gpu=True, c=c) else: - heatmap, prob, label = inc_inference(dataset, model_class, curr_path, patch_size=patch_size, stride=stride_size, beta=0.55, x_size=299, y_size=299, image_size=299, gpu=True, c=c) + heatmap, prob, label = inc_inference(dataset, model_class, curr_path, patch_size=patch_size, stride=stride_size, beta=0.7, x_size=299, y_size=299, image_size=299, gpu=True, c=c) else: if model_class != Inception3: heatmap, prob, label = full_inference_e2e(dataset, model_class, curr_path, patch_size=patch_size, stride=stride_size, batch_size=64, image_size=224, gpu=True, c=c) @@ -155,14 +155,16 @@ def selectedRegion(request): heatmap, prob, label = inc_inference(dataset, model_class, curr_path, patch_size=patch_size, stride=stride_size, beta=1.0, x0=calibrated_y1, y0=calibrated_x1, x_size=calibrated_h, y_size=calibrated_w, image_size=299, gpu=True, c=c) elif mode == "approximate": if model_class != Inception3: - heatmap, prob, label = inc_inference(dataset, model_class, curr_path, patch_size=patch_size, stride=stride_size, beta=0.55, x0=calibrated_y1, y0=calibrated_x1, x_size=calibrated_h, y_size=calibrated_w, image_size=224, gpu=True, c=c) + heatmap, prob, label = inc_inference(dataset, model_class, curr_path, patch_size=patch_size, stride=stride_size, beta=0.5, x0=calibrated_y1, y0=calibrated_x1, x_size=calibrated_h, y_size=calibrated_w, image_size=224, gpu=True, c=c) else: - heatmap, prob, label = inc_inference(dataset, model_class, curr_path, patch_size=patch_size, stride=stride_size, beta=0.55, x0=calibrated_y1, y0=calibrated_x1, x_size=calibrated_h, y_size=calibrated_w, image_size=299, gpu=True, c=c) + heatmap, prob, label = inc_inference(dataset, model_class, curr_path, patch_size=patch_size, stride=stride_size, beta=0.7, x0=calibrated_y1, y0=calibrated_x1, x_size=calibrated_h, y_size=calibrated_w, image_size=299, gpu=True, c=c) end_time = time.time() heatmap_path = './media/photos/heatmap_' + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(20)) + '.png' + low_prob = np.min(heatmap) + high_prob = np.max(heatmap) plt.imsave(heatmap_path, heatmap, cmap=plt.cm.jet_r) img = Image.open(heatmap_path) @@ -182,7 +184,7 @@ def selectedRegion(request): else: class_names = imagenet_class_names - return JsonResponse({'url':url, 'heatmap_url': heatmap_path[1:], 'prediction': class_names[label], 'estimate_time': estTime, 'actual_time': actTime}) + return JsonResponse({'url':url, 'heatmap_url': heatmap_path[1:], 'prediction': class_names[label], 'estimate_time': estTime, 'actual_time': actTime, 'low_prob':str(low_prob), 'high_prob':str(high_prob)}) def time_estimate(slope, intercept, stride, patch, width, height): diff --git a/code-release/ui/krypton_ui/krypton_ui/templates/index.html b/code-release/ui/krypton_ui/krypton_ui/templates/index.html index 47fcbf9..cee366e 100644 --- a/code-release/ui/krypton_ui/krypton_ui/templates/index.html +++ b/code-release/ui/krypton_ui/krypton_ui/templates/index.html @@ -20,9 +20,12 @@ float: left; width: 49%; padding: 5px; + display: flex; + align-items: center; + justify-content: center; } - /* Clear floats after image containers */ + /* Clear floats after image containers */ .row::after { content: ""; clear: both; @@ -153,9 +156,8 @@ -
-
+
Upload
@@ -163,22 +165,23 @@
-
- -
+
+ Download  sample images +