cchen-cc / SFDA-DPL

[MICCAI'21] Source-Free domain adaptive fundus image segmentation with denoised pseudo-labeling
51 stars 9 forks source link

How to view pseudolabels images? #8

Open rst1991 opened 1 year ago

rst1991 commented 1 year ago

Pseudolabels are saved in .npz format. How to visualize it ?

rst1991 commented 1 year ago

@cchen-cc Can you please help in generating pseudolabels. I am not able to visualize it.

cchen-cc commented 1 year ago

After reading the data from .npz files, you can then plot it out.

rst1991 commented 1 year ago

@cchen-cc I am able to read data from .npz file but I am not able to plot it.

import matplotlib.pyplot as plt import numpy as np from numpy import load from torchvision import transforms from PIL import Image import PIL

data = load('/data3/sfd/SFDA-DPL-main/generate_pseudo/pseudolabel_D2.npz', allow_pickle=True) lst = data.files for item in lst: print(item) print(data[item]) my_array=data[data.files[0]]

dfile = "/data3/sfd/SFDA-DPL-main/generate_pseudo/pseudolabel_D2.npz" images = np.load(dfile,allow_pickle=True)["arr_0"] tensor=images tran = transforms.ToPILImage() img = tran(tensor) img.show()

Screenshot from 2023-01-18 11-30-46

cchen-cc commented 1 year ago

You can use plt.imshow() to plot the image.

rst1991 commented 1 year ago

@cchen-cc import matplotlib.pyplot as plt import numpy as np from torchvision import transforms from PIL import Image import PIL

dfile = "/data3/sfd/SFDA-DPL-main/generate_pseudo/pseudolabel_D2.npz" images = np.load(dfile,allow_pickle=True)["arr_0"] plt.imshow(images)

Traceback (most recent call last): File "readlabel.py", line 51, in plt.imshow(images) File "/data3/rrd/rrd_py37/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2651, in imshow None else {}), kwargs) File "/data3/rrd/rrd_py37/lib/python3.7/site-packages/matplotlib/init.py", line 1565, in inner return func(ax, *map(sanitize_sequence, args), *kwargs) File "/data3/rrd/rrd_py37/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py", line 358, in wrapper return func(args, kwargs) File "/data3/rrd/rrd_py37/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py", line 358, in wrapper return func(*args, **kwargs) File "/data3/rrd/rrd_py37/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 5626, in imshow im.set_data(X) File "/data3/rrd/rrd_py37/lib/python3.7/site-packages/matplotlib/image.py", line 694, in set_data "float".format(self._A.dtype)) TypeError: Image data of dtype <U6 cannot be converted to float