Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pre_process method to convert NumPy array to PyTorch tensor #2480

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Sachin-NK
Copy link

📝 Description

This pull request fixes the pre_process method in the TorchInferencer to correctly handle NumPy arrays before performing PyTorch operations. The main changes include:

  • Adding a batch dimension to the input image if it has 3 dimensions.
  • Converting the NumPy array to a PyTorch tensor.
  • Moving the tensor to the specified device.

🛠️ Fixes #2452

✨ Changes

[ ] 🐞 Bug fix (non-breaking change which fixes an issue)

  • Updated pre_process method to add a batch dimension using np.expand_dims if the input image has 3 dimensions.
  • Converted the input image from a NumPy array to a PyTorch tensor using torch.from_numpy.
  • Moved the tensor to the specified device using the to method.

✅ Checklist

  • 📋 I have summarized my changes in the CHANGELOG and followed the guidelines for my type of change (skip for minor changes, documentation updates, and test enhancements).
  • 📚 I have made the necessary updates to the documentation (if applicable).
  • 🧪 I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).

@Sachin-NK
Copy link
Author

Fixed the issue by converting image to a PyTorch tensor before calling unsqueeze(). When you have some time, please take a look and let me know if any further adjustments are needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: AttributeError: 'numpy.ndarray' object has no attribute 'to'
1 participant