GeorgeCazenavette / mtt-distillation

Official code for our CVPR '22 paper "Dataset Distillation by Matching Training Trajectories"
https://georgecazenavette.github.io/mtt-distillation/
Other
395 stars 55 forks source link

Normalization of dataset #37

Closed f-amerehi closed 1 year ago

f-amerehi commented 1 year ago

Hi @GeorgeCazenavette

Hope that all is well. I'm trying to load images via images = torch.load("imagefruit/images_best.pt"). However, when I try to plot them, I get the error of

WARNING:matplotlib.image:Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).

How can I normalize the data? I tried minmax normalization but the outputs are opaque and not similar to the ones that you have in the here.

Thanks

GeorgeCazenavette commented 1 year ago

Hello :)

For purely visualization purposes, the images are clipped to mean +- 2.5 * std before normalizing to [0, 1]. There is an example of this in the code where the images are logged.

If you naively normalize to [0,1], the extreme pixel values in the distilled images will result in low overall visual contrast.

Hope this helps! If not, could you share what your images look like?

f-amerehi commented 1 year ago

Thank you @GeorgeCazenavette very much for quick reply! Here you are these are the images

image

The code is also here:

images = torch.load("imagefruit/images_best.pt")
labels = torch.load("imagefruit/labels_best.pt")

v = images
v_min = torch.min(v)
v_max = torch.max(v)
new_max = 1
new_min=0

v_p = (v - v_min)/(v_max - v_min)*(new_max - new_min) + new_min

col = 5
rows = math.ceil(len(v_p)/col)
fig,axs = plt.subplots(rows,col,figsize=(col*2,rows*2))

for (i,ax) in enumerate(axs.flatten()):
  image = v_p[i]
  pic = image.numpy().transpose((1,2,0))

  ax.imshow(pic)
  ax.axis('off')

plt.tight_layout()
plt.show()
GeorgeCazenavette commented 1 year ago

Yeah your images look correct, they'll just be prettier if you clip them before normalizing.

Check the section at line 256 of distill.py (I would link it directly, but I can't figure out how to do that from my phone.)

f-amerehi commented 1 year ago

Thank you @GeorgeCazenavette so much!

image