numpy.empty() data type not understood error on Google colab
numpy.empty() returns data type not understood exception on Google colab's default numpy library. I checked all questions in stackoverflow but didnt see related to this problem since i am using google colab. Here is full code and exception output:
Full code:
def diffMask(img1=None, img2=None, opt=None, dataset=None, args=None):
    netG = args[0]
    netB = args[1]
    netD = args[2]
    f = args[3]
    res_path = opt.results_Stage3
    res_folders = ['temp_masks',
                   'temp_Stage2',
                   'temp_ref',
                   'temp_diff',
                   'temp_Stage3',
                   'temp_skel',
                   'temp_res',
                   'temp_Stage1',
                   'temp_src']
    for x in res_folders:
        if os.path.isdir(&quot;{}{}&quot;.format(res_path, x)) == False:
            os.mkdir(&quot;{}{}&quot;.format(res_path, x))
    save_masks = &quot;{}{}&quot;.format(res_path, &quot;temp_masks&quot;)
    save_Stage2 = &quot;{}{}&quot;.format(res_path, &quot;temp_Stage2&quot;)
    save_ref = &quot;{}{}&quot;.format(res_path, &quot;temp_ref&quot;)
    save_diff = &quot;{}{}&quot;.format(res_path, &quot;temp_diff&quot;)
    save_Stage3 = &quot;{}{}&quot;.format(res_path, &quot;temp_Stage3&quot;)
    save_skel = &quot;{}{}&quot;.format(res_path, &quot;temp_skel&quot;)
    save_res = &quot;{}{}&quot;.format(res_path, &quot;temp_res&quot;)
    save_Stage1 = &quot;{}{}&quot;.format(res_path, &quot;temp_Stage1&quot;)
    save_src = &quot;{}{}&quot;.format(res_path, &quot;temp_src&quot;)

    resize2 = transforms.Resize(size=(128, 128))
    src, mask, style_img, target, gt_cloth, skel, cloth = dataset.get_img(&quot;{}_0.jpg&quot;.format(img1[:-6]),
                                                                          &quot;{}_1.jpg&quot;.format(img1[:-6]))
    src, mask, style_img, target, gt_cloth, skel, cloth = src.unsqueeze(0), mask.unsqueeze(0), style_img.unsqueeze(
        0), target.unsqueeze(0), gt_cloth.unsqueeze(0), skel.unsqueeze(0), cloth.unsqueeze(0)  # , face.unsqueeze(0)
    src1, mask1, style_img1, target1, gt_cloth1, skel1, cloth1 = Variable(src.cuda()), Variable(mask.cuda()), Variable(
        style_img.cuda()), Variable(target.cuda()), Variable(gt_cloth.cuda()), Variable(skel.cuda()), Variable(
        cloth.cuda())  # , Variable(face.cuda())
    src, mask, style_img, target, gt_cloth, skel, cloth = dataset.get_img(&quot;{}_0.jpg&quot;.format(img2[:-6]),
                                                                          &quot;{}_1.jpg&quot;.format(img2[:-6]))
    src, mask, style_img, target, gt_cloth, skel, cloth = src.unsqueeze(0), mask.unsqueeze(0), style_img.unsqueeze(
        0), target.unsqueeze(0), gt_cloth.unsqueeze(0), skel.unsqueeze(0), cloth.unsqueeze(0)  # , face.unsqueeze(0)
    src2, mask2, style_img2, target2, gt_cloth2, skel2, cloth2 = Variable(src.cuda()), Variable(mask.cuda()), Variable(
        style_img.cuda()), Variable(target.cuda()), Variable(gt_cloth.cuda()), Variable(skel.cuda()), Variable(
        cloth.cuda())

    gen_targ_Stage1, s_128, s_64, s_32, s_16, s_8, s_4 = netG(skel1, cloth2)  # gen_targ11 is structural change cloth
    gen_targ_Stage2, s_128, s_64, s_32, s_16, s_8, s_4 = netB(src1, gen_targ_Stage1,
                                                              skel1)  # gen_targ12 is Stage2 image

    # saving structural 
    pic_Stage2 = (torch.cat([gen_targ_Stage2], dim=0).data + 1) / 2.0
    #     save_dir = &quot;/home/np9207/PolyGan_res/temp_Stage2/&quot;
    save_image(pic_Stage2, '%s/%d_%s_%d.jpg' % (save_Stage2, f, img1[:-6], 0), nrow=1)

    msk1 = mask1[0, :, :, :].detach().cpu().permute(1, 2, 0)
    plt.imsave(&quot;{}/{}_{}_mask.jpg&quot;.format(save_masks, f, img1[:-6]), msk1, cmap=&quot;gray&quot;)

I got exception on this line:
plt.imsave(&quot;{}/{}_{}_mask.jpg&quot;.format(save_masks, f, img1[:-6]), msk1, cmap=&quot;gray&quot;)

Exception Output:
Traceback (most recent call last):
  File &quot;test.py&quot;, line 208, in test
    diffMask(image1, image2, opt, test_loader, args)
  File &quot;test.py&quot;, line 96, in diffMask
    plt.imsave(&quot;{}/{}_{}_mask.jpg&quot;.format(save_masks, f, img1[:-6]), msk1, cmap=&quot;gray&quot;)
  File &quot;/usr/local/lib/python3.6/dist-packages/matplotlib/pyplot.py&quot;, line 2066, in imsave
    return matplotlib.image.imsave(fname, arr, **kwargs)
  File &quot;/usr/local/lib/python3.6/dist-packages/matplotlib/image.py&quot;, line 1550, in imsave
    rgba = sm.to_rgba(arr, bytes=True)
  File &quot;/usr/local/lib/python3.6/dist-packages/matplotlib/cm.py&quot;, line 217, in to_rgba
    xx = np.empty(shape=(m, n, 4), dtype=x.dtype)
TypeError: data type not understood

Numpy Version : 1.18.5
Thank you in advance.

Thanks to @user2357112 @Rika and @hpaulj 's great helps, I found the cause of the problem and here is solution for those who is struggling  the same issue:
msk1 = msk1.numpy()

But then (probably) you will get ValueError: Floating point image RGB values must be in the 0..1 range. exception. You have to normalize your array. Thanks to him
def normalize(x):
    &quot;&quot;&quot;
    Normalize a list of sample image data in the range of 0 to 1
    : x: List of image data.  The image shape is (32, 32, 3)
    : return: Numpy array of normalized data
    &quot;&quot;&quot;
    return np.array((x - np.min(x)) / (np.max(x) - np.min(x)))

msk1 = normalize(msk1.numpy())

