Show_image() fails for torch.float16

show_image() function defined in fastai/torch_core.py throws ValueError: Unsupported dtype

y = torch.randn(24,24, dtype=torch.float16)
show_image(y);
Error in callback <function install_repl_displayhook.<locals>.post_execute at 0x7fa0f532e560> (for post_execute):
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/matplotlib/pyplot.py in post_execute()
    107             def post_execute():
    108                 if matplotlib.is_interactive():
--> 109                     draw_all()
    110 
    111             # IPython >= 2

13 frames
/usr/local/lib/python3.7/dist-packages/matplotlib/image.py in _resample(image_obj, data, out_shape, transform, resample, alpha)
    200                     alpha,
    201                     image_obj.get_filternorm(),
--> 202                     image_obj.get_filterrad())
    203     return out
    204 

It works fine for torch.float32, or torch.float64.
Can anybody please help?

I am using Google Colab Pro Version.

python       : 3.7.11
fastai       : 2.4.1
fastcore     : 1.3.20
fastprogress : 0.2.7
torch        : 1.9.0+cu102
torch cuda   : 10.2 / is **Not available**

Installing Matplotlib from source should fix the error. For more information, please check this out.

Cheers!

Thanks a lot. I assume that this fix is available in the next Matplotlib release. :+1: :slightly_smiling_face:

1 Like