mirror of
https://github.com/jantic/DeOldify.git
synced 2026-08-30 18:02:24 +08:00
Using Colab friendly array to image conversion
This commit is contained in:
@@ -496,24 +496,6 @@
|
||||
"!mkdir \"/content/drive/My Drive/deOldifyImages/results\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"colab": {},
|
||||
"colab_type": "code",
|
||||
"id": "695Tr-7IIFm5"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# workaround for saving images from colab (source https://stackoverflow.com/questions/48547660/attributeerror-module-pil-image-has-no-attribute-register-extensions) \n",
|
||||
"def register_extension(id, extension): Image.EXTENSION[extension.lower()] = id.upper()\n",
|
||||
"Image.register_extension = register_extension\n",
|
||||
"def register_extensions(id, extensions): \n",
|
||||
" for extension in extensions: register_extension(id, extension)\n",
|
||||
"Image.register_extensions = register_extensions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
|
||||
@@ -37,11 +37,15 @@ 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 misc.toimage(array)
|
||||
return self._convert_array_to_pil_image(array)
|
||||
|
||||
def _convert_array_to_pil_image(self, array:ndarray):
|
||||
return Image.fromarray((array*255).astype('uint8'))
|
||||
|
||||
def _save_result_image(self, source_path:Path, result:ndarray):
|
||||
result_path = self.results_dir/source_path.name
|
||||
misc.imsave(result_path, result)
|
||||
im = self._convert_array_to_pil_image(result)
|
||||
im.save(result_path)
|
||||
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user