tomgoldstein / loss-landscape

Code for visualizing the loss landscape of neural nets
MIT License
2.72k stars 388 forks source link

Getting " 2 indexing arguments for 1 dimensions" error when using "plot_trajectory.py" #48

Open alqurri77 opened 2 months ago

alqurri77 commented 2 months ago

I tried to use "plot_trajectory" with te command: plot_trajectory.py --model resnet56 --model_folder /tmp/ahmed --dir_type weights --prefix landscape/loss-landscape-master/all_models/my_model --suffix .pth --max_epoch 14

But I got this error:

/tmp/ahmed/landscape/loss-landscape-master/all_models/my_model5.pth  (0.0000, 0.0000)
Traceback (most recent call last):
  File "/tmp/ahmed/landscape/loss-landscape-master/plot_trajectory.py", line 66, in <module>
    plot_2D.plot_trajectory(proj_file, dir_file)
  File "/tmp/ahmed/landscape/loss-landscape-master/plot_2D.py", line 87, in plot_trajectory
    plt.plot(f['proj_xcoord'], f['proj_ycoord'], marker='.')
  File "/tmp/ahmed/ana/anaconda3/lib/python3.11/site-packages/matplotlib/pyplot.py", line 3578, in plot
    return gca().plot(
           ^^^^^^^^^^^
  File "/tmp/ahmed/ana/anaconda3/lib/python3.11/site-packages/matplotlib/axes/_axes.py", line 1721, in plot
    lines = [*self._get_lines(self, *args, data=data, **kwargs)]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/ahmed/ana/anaconda3/lib/python3.11/site-packages/matplotlib/axes/_base.py", line 303, in __call__
    yield from self._plot_args(
               ^^^^^^^^^^^^^^^^
  File "/tmp/ahmed/ana/anaconda3/lib/python3.11/site-packages/matplotlib/axes/_base.py", line 505, in _plot_args
    x = x[:, np.newaxis]
        ~^^^^^^^^^^^^^^^
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "/tmp/ahmed/ana/anaconda3/lib/python3.11/site-packages/h5py/_hl/dataset.py", line 758, in __getitem__
    return self._fast_reader.read(args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "h5py/_selector.pyx", line 361, in h5py._selector.Reader.read
  File "h5py/_selector.pyx", line 107, in h5py._selector.Selector.apply_args
ValueError: 2 indexing arguments for 1 dimensions

What does this error means?

alqurri77 commented 2 months ago

I fixed the above errror by changing

plt.plot(f['proj_xcoord'], f['proj_ycoord'], marker='.')

in "plot_trajectory" in "plot_2D.py" to

my_x_p=f['proj_xcoord']
my_y_p=f['proj_ycoord']
plt.plot( np.array( my_x_p [:]), np.array(my_y_p [:]), marker='.')

it seems it works now. But I got the below chart: image

But I was expecting something like the one in the paper: image

How to get similar like the one in the paper.

NOrangeeroli commented 3 weeks ago

Hi I'm trying to run the code but found the packages mentioned in README are too old, would be nice to know can you share a working requirements.txt ?
Best,