AttributeError: 'deeptrack.deeplay' has no attribute 'Model' and RuntimeError with channel mismatch #283
Replies: 3 comments
-
It should work if you make the following additional changes: import deeptrack.deeplay as dl
import torchmetrics as tm
import torch
unet_reg = dl.Regressor(
model=net,
loss=torch.nn.CrossEntropyLoss(),
optimizer=dl.Adam(lr=1e-3),
metrics=[tm.F1Score(task="multiclass", num_classes=3)],
).create()
data_pipeline = (((image_of_particles >> dt.MoveAxis(-1, 0)) & (image_of_particles >> get_target_image))
>> dt.pytorch.ToTensor(dtype=torch.float)) # This prepares the pipeline for PyTorch.
dataset = dt.pytorch.Dataset(data_pipeline, length=640, replace=0.01)
train_loader = torch.utils.data.DataLoader(dataset, batch_size=8, shuffle=True)
unet_trainer = dl.Trainer(max_epochs=200, accelerator="auto") # auto here should select automatically CPU/GPU.
unet_trainer.fit(unet_reg, train_loader) and for the image prediction: predicted_image = unet_reg.predict(input_image).softmax(1)
...
plt.imshow(input_image[i, 0, ...], cmap="gray")
... Please, check it and let us know if you need more help. Note: We're in the process to adapt all examples to DeepTarck2 2.0.0 to accommodate the shift to torch and deeplay from TensorFlow and Keras. |
Beta Was this translation helpful? Give feedback.
-
@LiYuan-SJTU We have now corrected the notebook and it's working. See: https://github.com/DeepTrackAI/DeepTrack2/blob/develop/examples/tutorials/03.%20distinguishing_particles_in_brightfield_tutorial.ipynb |
Beta Was this translation helpful? Give feedback.
-
Thank you for providing the updated version of When executing the following line: unet_trainer.fit(unet_reg, train_loader) I got the error: Thanks again for your assistance! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I downloaded the
03. distinguishing_particles_in_brightfield_tutorial.ipynb
from the tutorial and ran it locally. However, I encountered the following error when executing the code:To resolve this, I modified the code to use dl.Regressor instead of dl.Model:
This works, but then I encounter another error when executing the following code:
My pytorch version is 2.2.1 and python version is 3.11.5.
dl.Regressor
instead ofdl.Model correct
? If yes, how can I handle the RuntimeError related to channel mismatch in the following code?Thanks in advance for your help!
Beta Was this translation helpful? Give feedback.
All reactions