From d4389622e7a3b0cd22fafabdf79088e99b005514 Mon Sep 17 00:00:00 2001 From: zir Date: Mon, 2 Apr 2018 15:50:06 +0200 Subject: [PATCH 1/2] Add a tool to relocate the jpgs. --- caffevis/app.py | 2 +- caffevis/jpg_vis_loading_thread.py | 4 ++-- models/caffenet-yos/fetch.sh | 2 ++ models/caffenet-yos/relocate_jpgs.py | 27 +++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 models/caffenet-yos/relocate_jpgs.py diff --git a/caffevis/app.py b/caffevis/app.py index a91cc8c32..50987b85e 100644 --- a/caffevis/app.py +++ b/caffevis/app.py @@ -517,7 +517,7 @@ def _draw_layer_pane(self, pane): elif self.settings.caffevis_outputs_dir_folder_format == 'max_tracker_output': display_2D, display_3D, display_3D_highres, is_layer_summary_loaded = self.load_pattern_images_optimizer_format( default_layer_name, layer_dat_3D, n_tiles, pane, tile_cols, tile_rows, - self.state.pattern_first_only, file_search_pattern='maxim*.png') + self.state.pattern_first_only, file_search_pattern='maxim*.jpg') elif self.state.pattern_mode == PatternMode.WEIGHTS_HISTOGRAM: display_2D, display_3D, display_3D_highres, is_layer_summary_loaded = self.load_weights_histograms( diff --git a/caffevis/jpg_vis_loading_thread.py b/caffevis/jpg_vis_loading_thread.py index c204114c2..e5c6ea182 100644 --- a/caffevis/jpg_vis_loading_thread.py +++ b/caffevis/jpg_vis_loading_thread.py @@ -152,7 +152,7 @@ def run(self): else: captions = [] self.load_image_into_pane_max_tracker_format(state_layer_name, state_selected_unit, resize_shape, images, - file_search_pattern='maxim*.png', + file_search_pattern='maxim*.jpg', image_index_to_set=1, captions=captions, values=values) @@ -169,7 +169,7 @@ def run(self): values = self.get_score_values_for_max_input_images(state_layer_name, state_selected_unit) self.load_image_into_pane_max_tracker_format(state_layer_name, state_selected_unit, resize_shape, images, - file_search_pattern='deconv*.png', + file_search_pattern='deconv*.jpg', image_index_to_set=2, values=values) # Prune images that were not found: diff --git a/models/caffenet-yos/fetch.sh b/models/caffenet-yos/fetch.sh index c4d887e75..44150aa47 100755 --- a/models/caffenet-yos/fetch.sh +++ b/models/caffenet-yos/fetch.sh @@ -47,3 +47,5 @@ else echo echo "Rerun as \"$0 all\" to also fetch fc6 and fc7 unit visualizations (Warning: 4.5G more)" fi + +python relocate_jpgs.py \ No newline at end of file diff --git a/models/caffenet-yos/relocate_jpgs.py b/models/caffenet-yos/relocate_jpgs.py new file mode 100644 index 000000000..1a4ef3939 --- /dev/null +++ b/models/caffenet-yos/relocate_jpgs.py @@ -0,0 +1,27 @@ +import os +import shutil +deconv_dir = 'unit_jpg_vis/max_deconv' +maxim_dir = 'unit_jpg_vis/max_im' +opt_dir = 'unit_jpg_vis/regularized_opt' +output_dir = 'outputs' +layer_info = {'conv1':96, 'conv2':256, 'conv3':384, 'conv4':384, 'conv5':256, 'fc8':1000, 'prob':1000} +if not os.path.exists(output_dir): + os.mkdir(output_dir) +for key, value in layer_info.iteritems(): + deconv_layer_dir = os.path.join(deconv_dir, key) + maxim_layer_dir = os.path.join(maxim_dir, key) + opt_layer_dir = os.path.join(opt_dir, key) + dst_layer_dir = os.path.join(output_dir, key) + if not os.path.exists(dst_layer_dir): + os.mkdir(dst_layer_dir) + for unit_id in range(value): + unit_dir = os.path.join(dst_layer_dir, "unit_%04d" % unit_id) + if not os.path.exists(unit_dir): + os.mkdir(unit_dir) + deconv_unit_name = os.path.join(deconv_layer_dir, '%s_%04d.jpg' % (key, unit_id)) + opt_unit_name = os.path.join(opt_layer_dir, '%s_%04d_montage.jpg' % (key, unit_id)) + maxim_unit_name = os.path.join(maxim_layer_dir, '%s_%04d.jpg' % (key, unit_id)) + shutil.copyfile(deconv_unit_name, os.path.join(unit_dir, 'deconv.jpg')) + shutil.copyfile(opt_unit_name, os.path.join(unit_dir, 'opt.jpg')) + shutil.copyfile(maxim_unit_name, os.path.join(unit_dir, 'maxim.jpg')) + print("%s finished" % key) From a0d09743a5ea0d5e8fa2eb424545d09ff407b7ac Mon Sep 17 00:00:00 2001 From: zir Date: Sun, 8 Apr 2018 14:08:21 +0200 Subject: [PATCH 2/2] change back to 'maxim*.png' and 'deconv*.png' --- caffevis/app.py | 2 +- caffevis/jpg_vis_loading_thread.py | 4 ++-- models/caffenet-yos/relocate_jpgs.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/caffevis/app.py b/caffevis/app.py index 50987b85e..a91cc8c32 100644 --- a/caffevis/app.py +++ b/caffevis/app.py @@ -517,7 +517,7 @@ def _draw_layer_pane(self, pane): elif self.settings.caffevis_outputs_dir_folder_format == 'max_tracker_output': display_2D, display_3D, display_3D_highres, is_layer_summary_loaded = self.load_pattern_images_optimizer_format( default_layer_name, layer_dat_3D, n_tiles, pane, tile_cols, tile_rows, - self.state.pattern_first_only, file_search_pattern='maxim*.jpg') + self.state.pattern_first_only, file_search_pattern='maxim*.png') elif self.state.pattern_mode == PatternMode.WEIGHTS_HISTOGRAM: display_2D, display_3D, display_3D_highres, is_layer_summary_loaded = self.load_weights_histograms( diff --git a/caffevis/jpg_vis_loading_thread.py b/caffevis/jpg_vis_loading_thread.py index e5c6ea182..c204114c2 100644 --- a/caffevis/jpg_vis_loading_thread.py +++ b/caffevis/jpg_vis_loading_thread.py @@ -152,7 +152,7 @@ def run(self): else: captions = [] self.load_image_into_pane_max_tracker_format(state_layer_name, state_selected_unit, resize_shape, images, - file_search_pattern='maxim*.jpg', + file_search_pattern='maxim*.png', image_index_to_set=1, captions=captions, values=values) @@ -169,7 +169,7 @@ def run(self): values = self.get_score_values_for_max_input_images(state_layer_name, state_selected_unit) self.load_image_into_pane_max_tracker_format(state_layer_name, state_selected_unit, resize_shape, images, - file_search_pattern='deconv*.jpg', + file_search_pattern='deconv*.png', image_index_to_set=2, values=values) # Prune images that were not found: diff --git a/models/caffenet-yos/relocate_jpgs.py b/models/caffenet-yos/relocate_jpgs.py index 1a4ef3939..a1a98228d 100644 --- a/models/caffenet-yos/relocate_jpgs.py +++ b/models/caffenet-yos/relocate_jpgs.py @@ -21,7 +21,7 @@ deconv_unit_name = os.path.join(deconv_layer_dir, '%s_%04d.jpg' % (key, unit_id)) opt_unit_name = os.path.join(opt_layer_dir, '%s_%04d_montage.jpg' % (key, unit_id)) maxim_unit_name = os.path.join(maxim_layer_dir, '%s_%04d.jpg' % (key, unit_id)) - shutil.copyfile(deconv_unit_name, os.path.join(unit_dir, 'deconv.jpg')) + shutil.copyfile(deconv_unit_name, os.path.join(unit_dir, 'deconv.png')) shutil.copyfile(opt_unit_name, os.path.join(unit_dir, 'opt.jpg')) - shutil.copyfile(maxim_unit_name, os.path.join(unit_dir, 'maxim.jpg')) + shutil.copyfile(maxim_unit_name, os.path.join(unit_dir, 'maxim.png')) print("%s finished" % key)