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

AttributeError: 'NoneType' object has no attribute 'copy' #1699

Closed
andysingal opened this issue Dec 12, 2023 · 3 comments
Closed

AttributeError: 'NoneType' object has no attribute 'copy' #1699

andysingal opened this issue Dec 12, 2023 · 3 comments
Labels
🐛 Bug Something isn't working ❔ Question Further information is requested 🤷 Can't reproduce

Comments

@andysingal
Copy link

🐛 Describe the bug

for code:

import cv2
import torch
from super_gradients.training import models
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")

model = models.get("yolo_nas_s", pretrained_weights="coco").to(device)

model.predict_webcam(conf=0.7)

ERROR

/Users/ankushsingal/miniconda3/envs/snakes/bin/python /Users/ankushsingal/Desktop/YOLO/
Lecture_3_webcam/YOLO_NAS_webcam.py
The console stream is logged into /Users/ankushsingal/sg_logs/console.log
[2023-12-12 07:43:01] INFO - crash_tips_setup.py - Crash tips is enabled. You can set your environment variable to CRASH_HANDLER=FALSE to disable it
[2023-12-12 07:43:02] WARNING - __init__.py - Failed to import pytorch_quantization
[2023-12-12 07:43:02,376] torch.distributed.elastic.multiprocessing.redirects: [WARNING] NOTE: Redirects are currently not supported in Windows or MacOs.
[2023-12-12 07:43:07] WARNING - calibrator.py - Failed to import pytorch_quantization
[2023-12-12 07:43:07] WARNING - export.py - Failed to import pytorch_quantization
[2023-12-12 07:43:07] WARNING - selective_quantization_utils.py - Failed to import pytorch_quantization
[2023-12-12 07:43:07] WARNING - env_sanity_check.py - Failed to verify operating system: Deci officially supports only Linux kernels. Some features may not work as expected.
[2023-12-12 07:43:08] INFO - checkpoint_utils.py - License Notification: YOLO-NAS pre-trained weights are subjected to the specific license terms and conditions detailed in 
https://github.com/Deci-AI/super-gradients/blob/master/LICENSE.YOLONAS.md
By downloading the pre-trained weight files you agree to comply with these terms.
[2023-12-12 07:43:09] INFO - checkpoint_utils.py - Successfully loaded pretrained weights for architecture yolo_nas_s
2023-12-12 07:43:10.044 python[2136:64031] WARNING: AVCaptureDeviceTypeExternal is deprecated for Continuity Cameras. Please use AVCaptureDeviceTypeContinuityCamera and add NSCameraUseContinuityCameraDeviceType to your Info.plist.
Traceback (most recent call last):
  File "/Users/ankushsingal/Desktop/YOLO/Lecture_3_webcam/YOLO_NAS_webcam.py", line 8, in <module>
    model.predict_webcam(conf=0.7)
  File "/Users/ankushsingal/miniconda3/envs/snakes/lib/python3.10/site-packages/super_gradients/training/models/detection_models/customizable_detector.py", line 228, in predict_webcam
    pipeline.predict_webcam()
  File "/Users/ankushsingal/miniconda3/envs/snakes/lib/python3.10/site-packages/super_gradients/training/pipelines/pipelines.py", line 151, in predict_webcam
    video_streaming.run()
  File "/Users/ankushsingal/miniconda3/envs/snakes/lib/python3.10/site-packages/super_gradients/training/utils/media/stream.py", line 43, in run
    self._display_single_frame()
  File "/Users/ankushsingal/miniconda3/envs/snakes/lib/python3.10/site-packages/super_gradients/training/utils/media/stream.py", line 54, in _display_single_frame
    frame = self.frame_processing_fn(frame)
  File "/Users/ankushsingal/miniconda3/envs/snakes/lib/python3.10/site-packages/super_gradients/training/pipelines/pipelines.py", line 147, in _draw_predictions
    frame_prediction = next(iter(self._generate_prediction_result(images=[frame])))
  File "/Users/ankushsingal/miniconda3/envs/snakes/lib/python3.10/site-packages/super_gradients/training/pipelines/pipelines.py", line 164, in _generate_prediction_result
    yield from self._generate_prediction_result_single_batch(images)
  File "/Users/ankushsingal/miniconda3/envs/snakes/lib/python3.10/site-packages/super_gradients/training/pipelines/pipelines.py", line 189, in _generate_prediction_result_single_batch
    preprocessed_image, processing_metadata = self.image_processor.preprocess_image(image=image.copy())
AttributeError: 'NoneType' object has no attribute 'copy'

Versions

Collecting environment information...
PyTorch version: 2.1.1
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 14.0 (x86_64)
GCC version: Could not collect
Clang version: 15.0.0 (clang-1500.0.40.1)
CMake version: Could not collect
Libc version: N/A

Python version: 3.10.13 (main, Sep 11 2023, 08:39:02) [Clang 14.0.6 ] (64-bit runtime)
Python platform: macOS-10.16-x86_64-i386-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Intel(R) Core(TM) i5-8500 CPU @ 3.00GHz

Versions of relevant libraries:
[pip3] numpy==1.23.0
[pip3] onnx==1.13.0
[pip3] onnx-simplifier==0.4.35
[pip3] onnxruntime==1.13.1
[pip3] torch==2.1.1
[pip3] torchmetrics==0.8.0
[pip3] torchvision==0.16.1
[conda] numpy                     1.23.0                   pypi_0    pypi
[conda] torch                     2.1.1                    pypi_0    pypi
[conda] torchmetrics              0.8.0                    pypi_0    pypi
[conda] torchvision               0.16.1                   pypi_0    pypi
@BloodAxe
Copy link
Collaborator

It looks like the problem is with OpenCV video capture which is not able to grab frames from the webcam. Maybe you need to give explicit permissions for the process to access webcamera.
Can you please check whether this code works for you and shows a video:

cap = cv2.VideoCapture(cv2.CAP_ANY)
while cv2.waitKey(1) != ord('q'):
   _ret, frame = cap.read()
   cv2.imshow("Webcam", frame)

@andysingal
Copy link
Author

gi

here is my current code:
it works with the code you share, how to make it work with the below code

import cv2
import torch
from super_gradients.training import models
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")

model = models.get("yolo_nas_s", pretrained_weights="coco").to(device)

model.predict_webcam(conf=0.7)

@BloodAxe
Copy link
Collaborator

@andysingal I was not able to reproduce the issue with the latest build of SG. Which version of SG are you using?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working ❔ Question Further information is requested 🤷 Can't reproduce
Projects
None yet
Development

No branches or pull requests

2 participants