From 13060fbf181fdc2d57b4905768a19e10812cbd26 Mon Sep 17 00:00:00 2001 From: vbhavank Date: Tue, 7 Jul 2020 13:50:53 -0400 Subject: [PATCH 1/2] Fix Py 2 to 3 encoding errors --- .../algorithms/descriptor_generator/caffe_descriptor.py | 8 +++----- .../web/search_app/modules/file_upload/FileUploadMod.py | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/python/smqtk/algorithms/descriptor_generator/caffe_descriptor.py b/python/smqtk/algorithms/descriptor_generator/caffe_descriptor.py index 48d68e4dc..2ab64c39d 100644 --- a/python/smqtk/algorithms/descriptor_generator/caffe_descriptor.py +++ b/python/smqtk/algorithms/descriptor_generator/caffe_descriptor.py @@ -181,11 +181,9 @@ def _setup_network(self): # - ``caffe.TEST`` indicates phase of either TRAIN or TEST self._log.debug("Initializing network") self._log.debug("Loading Caffe network from network/model configs") - self.network = caffe.Net(self.network_prototxt.write_temp(), + self.network = caffe.Net(self.network_prototxt, caffe.TEST, - weights=self.network_model.write_temp()) - self.network_prototxt.clean_temp() - self.network_model.clean_temp() + weights=self.network_model) # Assuming the network has a 'data' layer and notion of data shape self.net_data_shape = self.network.blobs[self.data_layer].data.shape self._log.debug("Network data shape: %s", self.net_data_shape) @@ -201,7 +199,7 @@ def _setup_network(self): if self.image_mean is not None: self._log.debug("Loading image mean (reducing to single pixel " "mean)") - image_mean_bytes = self.image_mean.get_bytes() + image_mean_bytes = open(self.image_mean, "rb").read() try: a = numpy.load(io.BytesIO(image_mean_bytes)) self._log.info("Loaded image mean from numpy bytes") diff --git a/python/smqtk/web/search_app/modules/file_upload/FileUploadMod.py b/python/smqtk/web/search_app/modules/file_upload/FileUploadMod.py index a0fb7ee65..eed95aba3 100644 --- a/python/smqtk/web/search_app/modules/file_upload/FileUploadMod.py +++ b/python/smqtk/web/search_app/modules/file_upload/FileUploadMod.py @@ -4,6 +4,7 @@ import os import tempfile +from six import BytesIO from six.moves import cStringIO as StringIO from smqtk.utils import SmqtkObject @@ -82,7 +83,7 @@ def upload_file(): # - Need to explicitly copy the buffered data as the file object # closes between chunk messages. self._file_chunks.setdefault(fid, {})[current_chunk] \ - = StringIO(chunk_data.read()) + = BytesIO(chunk_data.read()) message = "Uploaded chunk #%d of %d for file '%s'" \ % (current_chunk, total_chunks, filename) From 654f69e0db89ce7b0a2fd13b27ef503ed4523e6b Mon Sep 17 00:00:00 2001 From: vbhavank Date: Tue, 14 Jul 2020 14:40:57 -0400 Subject: [PATCH 2/2] Removed unused imports --- .../web/search_app/modules/file_upload/FileUploadMod.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python/smqtk/web/search_app/modules/file_upload/FileUploadMod.py b/python/smqtk/web/search_app/modules/file_upload/FileUploadMod.py index eed95aba3..accf69fe4 100644 --- a/python/smqtk/web/search_app/modules/file_upload/FileUploadMod.py +++ b/python/smqtk/web/search_app/modules/file_upload/FileUploadMod.py @@ -5,7 +5,6 @@ import tempfile from six import BytesIO -from six.moves import cStringIO as StringIO from smqtk.utils import SmqtkObject from smqtk.utils.file import safe_create_dir @@ -46,7 +45,7 @@ def __init__(self, name, parent_app, working_directory, url_prefix=None): # Top level key is the file ID of the upload. The dictionary # underneath that is the index ID'd chunks. When all chunks are # present, the file is written and the entry in this map is removed. - #: :type: dict of (str, dict of (int, StringIO)) + #: :type: dict of (str, dict of (int, BytesIO)) self._file_chunks = {} # Lock per file ID so as to not collide when uploading multiple chunks #: :type: dict of (str, RLock) @@ -179,7 +178,7 @@ def _write_file_chunks(self, chunk_map, file_extension=''): Returned file path should be manually removed by the user. :param chunk_map: Mapping of integer index to file-like chunk - :type chunk_map: dict of (int, StringIO) + :type chunk_map: dict of (int, BytesIO) :param file_extension: String extension to suffix the temporary file with :type file_extension: str