Skip to content

Instantly share code, notes, and snippets.

@andreh7
Last active May 5, 2023 14:14
Show Gist options
  • Save andreh7/74221b7140594d1f8062788729a62524 to your computer and use it in GitHub Desktop.
Save andreh7/74221b7140594d1f8062788729a62524 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zmadscientist
Copy link

zmadscientist commented Sep 15, 2020

Your article is a great teaching moment - but I have run into issues running your code as is - specifically during training:

starting training

IndexError Traceback (most recent call last)
in ()
47 input_var = Variable(torch.from_numpy(this_inputs))
48
---> 49 output = model.forward(input_var)
50
51 # build a PyTorch variable with the target value

in forward(self, input)
40 input = input.data.numpy()
41
---> 42 return self.single_coord_func(input[:,0], 0) + self.single_coord_func(input[:,1], 1)

in single_coord_func(self, input, coord)
24 # fold in underflow/overflow bins
25 indices = np.clip(indices, 0, self.n_bins_xy[coord] - 1)
---> 26 return torch.cat([ self.coeffs[indices[row], coord] for row in range(len(input)) ])
27
28 #----------------------------------------

in (.0)
24 # fold in underflow/overflow bins
25 indices = np.clip(indices, 0, self.n_bins_xy[coord] - 1)
---> 26 return torch.cat([ self.coeffs[indices[row], coord] for row in range(len(input)) ])
27
28 #----------------------------------------

IndexError: only integers, slices (:), ellipsis (...), None and long or byte Variables are valid indices (got numpy.float32)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment