cellpose icon indicating copy to clipboard operation
cellpose copied to clipboard

"element 0 of tensors does not require grad" when training model

Open ktyssowski opened this issue 2 years ago • 2 comments

When I try to train my model (through the GUI), I get the following error:

Traceback (most recent call last):
  File "/Users/kelsey/cellpose/cellpose/gui/gui.py", line 1618, in new_model
    self.train_model()
  File "/Users/kelsey/cellpose/cellpose/gui/gui.py", line 1642, in train_model
    self.new_model_path = self.model.train(self.train_data, self.train_labels, 
  File "/Users/kelsey/cellpose/cellpose/models.py", line 784, in train
    model_path = self._train_net(train_data, train_flows, 
  File "/Users/kelsey/cellpose/cellpose/core.py", line 892, in _train_net
    train_loss = self._train_step(imgi, lbl)
  File "/Users/kelsey/cellpose/cellpose/core.py", line 745, in _train_step
    loss.backward()
  File "/Users/kelsey/mambaforge/envs/cellpose-env/lib/python3.9/site-packages/torch/_tensor.py", line 488, in backward
    torch.autograd.backward(
  File "/Users/kelsey/mambaforge/envs/cellpose-env/lib/python3.9/site-packages/torch/autograd/__init__.py", line 197, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

I'm running on a mac with an M1 chip, so I had to follow the instructions here to get it running on GPU (which it appears to be doing), but not sure if I'm having issues b/c of that

ktyssowski avatar Feb 13 '23 22:02 ktyssowski

just found a relevant thread on this here: https://forum.image.sc/t/cellpose-on-macos-m1-pro-apple-silicon-arm64/68018/30 starting yesterday (2/12/23)

ktyssowski avatar Feb 13 '23 23:02 ktyssowski

PR #668 might be the fix, we'll look into it.

mrariden avatar May 06 '23 00:05 mrariden