Comments (6)
π Hello @codinglearningnovice, thank you for your interest in Ultralytics YOLOv8 π! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.
If this is a π Bug Report, please provide a minimum reproducible example to help us debug it.
If this is a custom training β Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.
Join the vibrant Ultralytics Discord π§ community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.
Install
Pip install the ultralytics
package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.
pip install ultralytics
Environments
YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
- Notebooks with free GPU:
- Google Cloud Deep Learning VM. See GCP Quickstart Guide
- Amazon Deep Learning AMI. See AWS Quickstart Guide
- Docker Image. See Docker Quickstart Guide
Status
If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.
from ultralytics.
@codinglearningnovice hello,
Thank you for reaching out and providing detailed information about your issue. It looks like you're encountering an error because the results
object is a list of Results
objects, and you're trying to access the masks
attribute directly from the list.
To resolve this, you need to iterate over the results
list and then access the masks
attribute from each Results
object. Here's a modified version of your code snippet that should work:
while(count < TRAIN_SIZE):
try:
ret, frame = cap.read()
if currentFrame % FRAME_SKIP == 0:
count += 1
if count % int(TRAIN_SIZE/10) == 0:
print(str((count/TRAIN_SIZE)*100) + "% done")
# Perform human segmentation
results = model(frame)
for result in results:
person_masks = result.masks[result.boxes.cls == 0]
person_mask_3ch = cv2.cvtColor(person_masks, cv2.COLOR_GRAY2BGR)
masked_frame = cv2.bitwise_and(frame, person_mask_3ch)
inverted_mask = cv2.bitwise_not(person_mask_3ch)
result_frame = cv2.bitwise_and(masked_frame, inverted_mask)
resized_frame = cv2.resize(result_frame, (output_width, output_height))
name = 'trydata/resized_frame.jpg' + str(count) + '.jpg'
cv2.imwrite(name, resized_frame)
video.write(resized_frame.astype('uint8'))
except Exception as e:
print(e)
break
currentFrame += 1
print(str(count) + " Frames collected")
cap.release()
video.release()
Additionally, please ensure that you are using the latest versions of torch
and ultralytics
. You can upgrade them using the following commands:
pip install --upgrade torch ultralytics
If the issue persists, please provide a minimum reproducible example so we can investigate further. You can find more details on how to create one here.
I hope this helps! If you have any further questions, feel free to ask. π
from ultralytics.
thanks for your reply, tried this, it doesnt give me the result, it issues this error below
0: 384x640 1 person, 190.0ms
Speed: 3.1ms preprocess, 190.0ms inference, 3.8ms postprocess per image at shape (1, 3, 384, 640)
OpenCV(4.8.0) π error: (-5:Bad argument) in function 'cvtColor'
Overload resolution failed:
- src is not a numpy array, neither a scalar
- Expected Ptrcv::UMat for argument 'src'
1 Frames collected
am i doing something wrongly?
from ultralytics.
Hello @codinglearningnovice,
Thank you for your update. It looks like the error you're encountering is related to the cvtColor
function from OpenCV, which expects a numpy array but is receiving a different type.
To help us investigate further, could you please provide a minimum reproducible example of your code? This will allow us to reproduce the issue on our end and find a solution more effectively. You can find guidelines on how to create one here.
In the meantime, let's ensure that the person_masks
variable is indeed a numpy array before passing it to cvtColor
. Hereβs a revised snippet that includes a check:
while(count < TRAIN_SIZE):
try:
ret, frame = cap.read()
if currentFrame % FRAME_SKIP == 0:
count += 1
if count % int(TRAIN_SIZE/10) == 0:
print(str((count/TRAIN_SIZE)*100) + "% done")
# Perform human segmentation
results = model(frame)
for result in results:
person_masks = result.masks[result.boxes.cls == 0].numpy() # Ensure masks are numpy arrays
person_mask_3ch = cv2.cvtColor(person_masks, cv2.COLOR_GRAY2BGR)
masked_frame = cv2.bitwise_and(frame, person_mask_3ch)
inverted_mask = cv2.bitwise_not(person_mask_3ch)
result_frame = cv2.bitwise_and(masked_frame, inverted_mask)
resized_frame = cv2.resize(result_frame, (output_width, output_height))
name = 'trydata/resized_frame.jpg' + str(count) + '.jpg'
cv2.imwrite(name, resized_frame)
video.write(resized_frame.astype('uint8'))
except Exception as e:
print(e)
break
currentFrame += 1
print(str(count) + " Frames collected")
cap.release()
video.release()
Additionally, please ensure you are using the latest versions of torch
and ultralytics
. You can upgrade them using the following commands:
pip install --upgrade torch ultralytics
If the issue persists, please share the minimum reproducible example so we can assist you further. Thank you for your cooperation! π
from ultralytics.
Bug description:
When running inference on a video to segment the person and manipulate each frame, I get an error related to the expected input from the cv2.cvt, seems to be a type mismatch
MRE:
import cv2
from ultralytics import YOLO
# Load the YOLOv8 segmentation model
model = YOLO("yolov8n-seg.pt")
cap = cv2.VideoCapture('dancee.mp4')
output_width, output_height = 96, 64 # Adjust as needed
video = cv2.VideoWriter('output_video.mp4', cv2.VideoWriter_fourcc(*'mp4v'), 30, (output_width, output_height))
# Perform human segmentation
results = model(frame)
for result in results:
person_masks = result.masks[result.boxes.cls == 0].numpy() # Ensure masks are numpy arrays
person_mask_3ch = cv2.cvtColor(person_masks, cv2.COLOR_GRAY2BGR)
masked_frame = cv2.bitwise_and(frame, person_mask_3ch)
inverted_mask = cv2.bitwise_not(person_mask_3ch)
result_frame = cv2.bitwise_and(masked_frame, inverted_mask)
resized_frame = cv2.resize(result_frame, (output_width, output_height))
name = 'trydata/resized_frame.jpg' + str(count) + '.jpg'
cv2.imwrite(name, resized_frame)
video.write(resized_frame.astype('uint8'))
except Exception as e:
print(e)
break
currentFrame += 1
print(str(count) + " Frames collected")
cap.release()
video.release()
Error message:
OpenCV(4.8.0) π error: (-5:Bad argument) in function 'cvtColor'
Overload resolution failed:
- src is not a numpy array, neither a scalar
- Expected Ptrcv::UMat for argument 'src'
Dependencies:
ultralytics==8.2.0
from ultralytics.
Hello @codinglearningnovice,
Thank you for providing a detailed description of the issue and the minimum reproducible example (MRE). It looks like the error is due to a type mismatch when using cv2.cvtColor
. Let's ensure that the person_masks
variable is indeed a numpy array before passing it to cv2.cvtColor
.
First, please make sure you are using the latest versions of torch
and ultralytics
. You can upgrade them using the following commands:
pip install --upgrade torch ultralytics
Hereβs a revised version of your code snippet that includes a check to ensure person_masks
is a numpy array:
import cv2
from ultralytics import YOLO
# Load the YOLOv8 segmentation model
model = YOLO("yolov8n-seg.pt")
cap = cv2.VideoCapture('dancee.mp4')
output_width, output_height = 96, 64 # Adjust as needed
video = cv2.VideoWriter('output_video.mp4', cv2.VideoWriter_fourcc(*'mp4v'), 30, (output_width, output_height))
count = 0
TRAIN_SIZE = 1000 # Adjust as needed
FRAME_SKIP = 5 # Adjust as needed
currentFrame = 0
while count < TRAIN_SIZE:
try:
ret, frame = cap.read()
if not ret:
break
if currentFrame % FRAME_SKIP == 0:
count += 1
if count % int(TRAIN_SIZE / 10) == 0:
print(f"{(count / TRAIN_SIZE) * 100}% done")
# Perform human segmentation
results = model(frame)
for result in results:
person_masks = result.masks[result.boxes.cls == 0].numpy() # Ensure masks are numpy arrays
if person_masks.size == 0:
continue # Skip if no person masks are found
person_mask_3ch = cv2.cvtColor(person_masks[0], cv2.COLOR_GRAY2BGR) # Convert the first mask to 3 channels
masked_frame = cv2.bitwise_and(frame, person_mask_3ch)
inverted_mask = cv2.bitwise_not(person_mask_3ch)
result_frame = cv2.bitwise_and(masked_frame, inverted_mask)
resized_frame = cv2.resize(result_frame, (output_width, output_height))
name = f'trydata/resized_frame_{count}.jpg'
cv2.imwrite(name, resized_frame)
video.write(resized_frame.astype('uint8'))
except Exception as e:
print(e)
break
currentFrame += 1
print(f"{count} Frames collected")
cap.release()
video.release()
This code ensures that person_masks
is a numpy array and handles cases where no person masks are found. Additionally, it converts the first mask to 3 channels before applying cv2.cvtColor
.
If the issue persists, please provide any additional details or errors you encounter. This will help us further investigate and provide a more accurate solution.
Thank you for your patience and cooperation! π
from ultralytics.
Related Issues (20)
- New YOLOv# Format for Pose Estimation with Keypoints Labels HOT 2
- Error after running make and ./Yolov8CPPInference in C++ HOT 3
- rtdetr fp16 inference HOT 4
- Simple question: How can I check the visual result of tracking video in Colab? HOT 2
- got an unexpected keyword argument 'allow_empty HOT 3
- How to publish an application to the client in python and run it using the GPU HOT 13
- When predicting, does yolov8's behavior change when there are different sized images in the input image list? HOT 2
- Yolov9 onnx export HOT 3
- Trainning not improving: Decreasing mAP and Early Stopping at Epoch 100 HOT 1
- Training on a new dataset based on best.pt HOT 7
- The effect of the random function HOT 3
- During validation, the result is different when setting the "save_txt" is True or False HOT 5
- SPAM HOT 2
- Erro when export yolo8n.pt to yolov8n.engine HOT 14
- When I use device='cpu', I always get' Process finished with exit code-1073741819 (0xC0000005) ' HOT 10
- Predict result HOT 2
- How to determine which predict layer is responsible for detection ? HOT 4
- about drawing the ground truth box HOT 1
- YOLOv8 OBB height issues HOT 1
- Custom Data Training for Action Recognition with YOLOv8 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ultralytics.