Browse Source

Another attempt to fix colab pil issue (wat wat wat)

Jason Antic 6 years ago
parent
commit
60754cf022
2 changed files with 11 additions and 6 deletions
  1. 9 0
      DeOldify_colab.ipynb
  2. 2 6
      fasterai/visualize.py

+ 9 - 0
DeOldify_colab.ipynb

@@ -32,6 +32,15 @@
     "NEW: You can now load your files from you own Drive, check the last cell of the notebook for more information."
    ]
   },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "ip install -Iv Pillow==5.3.0"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,

+ 2 - 6
fasterai/visualize.py

@@ -37,15 +37,11 @@ class ModelImageVisualizer():
     def get_transformed_image_as_pil(self, path:str, model:nn.Module, sz:int=None, tfms:[Transform]=[])->Image:
         path = Path(path)
         array = self.get_transformed_image_ndarray(path, model, sz, tfms=tfms)
-        return self._convert_array_to_pil_image(array)
-
-    def _convert_array_to_pil_image(self, array:ndarray):
-        return Image.fromarray((array*255).astype('uint8'))
+        return misc.toimage(array)
 
     def _save_result_image(self, source_path:Path, result:ndarray):
         result_path = self.results_dir/source_path.name
-        im = self._convert_array_to_pil_image(result)
-        im.save(result_path)
+        misc.imsave(result_path, result)
 
     def plot_images_from_image_sets(self, image_sets:[ModelImageSet], validation:bool, figsize:(int,int)=(20,20), 
             max_columns:int=6, immediate_display:bool=True):