Skip to content

Fix CUDA/CPU tensor mismatch in image classifier prediction#679

Open
Irozuku wants to merge 1 commit into
developfrom
fix/image-classifier-predict-device
Open

Fix CUDA/CPU tensor mismatch in image classifier prediction#679
Irozuku wants to merge 1 commit into
developfrom
fix/image-classifier-predict-device

Conversation

@Irozuku
Copy link
Copy Markdown
Collaborator

@Irozuku Irozuku commented Jun 5, 2026

Summary

Loaded image classifier checkpoints rebuild the backbone on CPU (torch.load(..., map_location="cpu")), but predict moved only the input images to the device. This caused a RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same during prediction. The model is now moved to the device before inference in every image classifier.


Type of Change

  • Backend change
  • Frontend change
  • CI / Workflow change
  • Build / Packaging change
  • Bug fix
  • Documentation

Testing

  • On a CUDA machine, train an image classifier, then run a prediction on a saved/loaded model (fresh process) and confirm it completes without the CUDA/CPU tensor type mismatch.
  • Verify prediction still works on a CPU-only device.

Changes (by file)

  • DashAI/back/models/base_torchvision_image_classifier.py: add self.model.to(self.device) before the eval loop in predict (covers ResNet18, ResNet50, EfficientNet).
  • DashAI/back/models/cnn_image_classifier.py: same fix in predict.
  • DashAI/back/models/lenet5_image_classifier.py: same fix in predict.
  • DashAI/back/models/mlp_image_classifier.py: same fix in predict.

Loaded checkpoints rebuild the backbone on CPU, but predict moved
only the input images to the device, causing a CUDA/CPU tensor type
mismatch. Move the model to the device before inference in all image
classifiers (MLP, CNN, LeNet5, ResNet18/50, EfficientNet).
@Irozuku Irozuku added bug Something isn't working back Backend work labels Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

back Backend work bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant