roboflow / notebooks

Examples and tutorials on using SOTA computer vision models and techniques. Learn everything from old-school ResNet, through YOLO and object-detection transformers like DETR, to the latest models like Grounding DINO and SAM.
https://roboflow.com/models
4.89k stars 759 forks source link

plotting error dinov2-classification #155

Closed c1scott closed 1 year ago

c1scott commented 1 year ago

Search before asking

Notebook name

Dinov2-classification https://github.com/roboflow/notebooks/blob/main/notebooks/dinov2-classification.ipynb

Bug

Running input_file = "MIT-Indoor-Scene-Recognition-5/test/elevator/elevator_google_0053_jpg.rf.41487c3b9c1690a5de26ee0218452627.jpg"

new_image = load_image(input_file)

%matplotlib inline sv.plot_image(image=new_image, size=(16, 16))

with torch.no_grad(): embedding = dinov2_vits14(new_image.to(device))

prediction = clf.predict(np.array(embedding[0].cpu()).reshape(1, -1))

print()
print("Predicted class: " + prediction[0])

i got


error Traceback (most recent call last) in <cell line: 6>() 4 5 get_ipython().run_line_magic('matplotlib', 'inline') ----> 6 sv.plot_image(image=new_image, size=(16, 16)) 7 8 with torch.no_grad():

/usr/local/lib/python3.10/dist-packages/supervision/utils/notebook.py in plot_image(image, size, cmap) 33 plt.imshow(image, cmap=cmap) 34 else: ---> 35 plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) 36 37 plt.axis("off")

error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'cvtColor'

Overload resolution failed:

  • src is not a numpy array, neither a scalar
  • Expected Ptr for argument 'src' <Figure size 1600x1600 with 0 Axes>

Environment

Google Colab, GPU T4 runtime

Minimal Reproducible Example

run all the cells (authorize roboflow when prompted), when you get to the last runnable cell

input_file = "MIT-Indoor-Scene-Recognition-5/test/elevator/elevator_google_0053_jpg.rf.41487c3b9c1690a5de26ee0218452627.jpg"

new_image = load_image(input_file)

%matplotlib inline sv.plot_image(image=new_image, size=(16, 16))

with torch.no_grad(): embedding = dinov2_vits14(new_image.to(device))

prediction = clf.predict(np.array(embedding[0].cpu()).reshape(1, -1))

print()
print("Predicted class: " + prediction[0])

if you run it you will see the error reproduced
however, the classification works and is correct

Additional

No response

Are you willing to submit a PR?

github-actions[bot] commented 1 year ago

👋 Hello @c1scott, thank you for leaving an issue on Roboflow Notebooks.

🐞 Bug reports

If you are filing a bug report, please be as detailed as possible. This will help us more easily diagnose and resolve the problem you are facing. To learn more about contributing, check out our Contributing Guidelines.

If you require support with custom code that is not part of Roboflow Notebooks, please reach out on the Roboflow Forum or on the GitHub Discussions page associated with this repository.

💬 Get in touch

Do you have more questions about Roboflow that we haven't responded to yet? Feel free to ask them on the Roboflow Discuss forum. Our developer advocates and community team actively respond to questions there.

To ask questions about Notebooks, head over to the GitHub Discussions section of this repository.

SkalskiP commented 1 year ago

Hi @c1scott 👋🏻 Let me take a look.

SkalskiP commented 1 year ago

@capjamesg could you take a look at this notebook? I did some initial investigation. It looks like new_image in this line:

new_image = load_image(input_file)

It is a PyTorch tensor, but you pass it to plot_image. plot_image can only take Numpy arrays.

capjamesg commented 1 year ago

@c1scott Thank you for the report! I have filed a PR to fix the notebook.

In any case, you can use this code to show the image:

%matplotlib inline
sv.plot_image(image=cv2.imread(input_file), size=(8, 8))

This will open the image with cv2 and display it using supervision.

capjamesg commented 1 year ago

This issue was fixed in PR #157 so I am closing this issue.