1. 程式人生 > 其它 >TypeError: Cannot handle this data type: (1, 1, 6), |u1

TypeError: Cannot handle this data type: (1, 1, 6), |u1

PIL_im=Image.fromarray(np.uint8(img)) PIL_att=Image.fromarray(np.uint8(one_map)).convert('RGB') 執行一部分之後報錯 TypeError: Cannot handle this data type: (1, 1, 6), |u1 第一個解決方案 PIL需要的格式是(W,H,C),而資料集的格式是(C,W,H)所以要進行轉換,把(C,W,H)變為(W,H,C) 把最上邊兩行程式碼改成 PIL_im=Image.fromarray(np.uint8(img.transpose(1,2,0))) PIL_att=Image.fromarray(np.uint8(one_map.transpose(1,2,0))).convert('RGB')
這個方法我的程式多運行了一步。。希望的花花就這麼沒有了 第二個方案 有的人說python2.7版本解決了這個問題,我換成2.7版本執行的確是解決了這個問題,但是會出現滿螢幕警告,影響執行速度 警告:UserWarning: masked_fill_ received a mask with dtype torch.uint8, this behavior is now deprecated,please use a mask with dtype torch.bool instead. 解決方案:(原文:https://github.com/microsoft/IRNet/issues/5) change the return oflength_array_to_mask_tensor()
/table_dict_to_mask_tensor()/pred_col_mask()

frommask = torch.ByteTensor(mask)tomask = torch.BoolTensor(mask).