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

Why didn't I get results in my video test? #2277

Closed
Kylinb opened this issue Feb 23, 2021 · 14 comments
Closed

Why didn't I get results in my video test? #2277

Kylinb opened this issue Feb 23, 2021 · 14 comments

Comments

@Kylinb
Copy link

Kylinb commented Feb 23, 2021

Hi,author!
/home/kylinb/anaconda3/envs/yolov5/bin/python /home/kylinb/PycharmProjects/yolov5/detect.py
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', exist_ok=False, img_size=640, iou_thres=0.45, name='exp', project='runs/detect', save_conf=False, save_txt=False, source='/home/kylinb/PycharmProjects/yolov5/1.mp4', update=False, view_img=False, weights='/home/kylinb/PycharmProjects/yolov5/runs/train/exp2/weights/best.pt')
YOLOv5 v4.0-63-g73a0669 torch 1.7.1 CUDA:0 (GeForce RTX 2070 with Max-Q Design, 7982.3125MB)

Fusing layers...
Model Summary: 224 layers, 7056607 parameters, 0 gradients, 16.3 GFLOPS
video 1/1 (1/-9223372036854775808) /home/kylinb/PycharmProjects/yolov5/1.mp4: 384x640 4 pigs, Done. (0.009s)

That's the problem. When I test a video,the result just like above. No video display, no video save. But the folder 'exp' would be created. Obviously, the folder is empty. It works only when testing pictures.

@Kylinb Kylinb added the bug Something isn't working label Feb 23, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2021

👋 Hello @Kylinb, thank you for your interest in 🚀 YOLOv5! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:

$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

@Kylinb we use cv2 for video loading, so you may want to create a simple cv2 loop to see what's going wrong.

You might also try exporting to a different format, or using one of our verified environments in the message above.

@VinayChaudhari1996
Copy link

VinayChaudhari1996 commented Mar 4, 2021

Hi , @glenn-jocher @Kylinb

I'm also getting same issue.

  1. After giving video source (.MP4 or .mkv)
    And successful run new (+Exp) empty folder is created,

  2. On colab it says fail to connect internal server X.

I think it trying to open video via cv2.show and this method is not working on colab.
Beacuse they have internal package for same.

So , How can I saved detected bounding box generated video with save (TXT , Labels) etc.

like image ?

Thanks ,

@glenn-jocher
Copy link
Member

@VinayChaudhari1996 inference works correctly in Colab notebook on videos. Tested myself today March 4th.
Screen Shot 2021-03-04 at 5 17 01 PM

@glenn-jocher
Copy link
Member

To save txt use --save-txt. See detect.py argparser for all arguments.

@JOSHUAWENJZ
Copy link

@Kylinb Hi, Buddy! I think I find what is your problem. You need pay attention to your video encoding format. I just test some videos. And when I test a video with encoding format of 'hevc'(‘hevc’ is just a encoding style of H.265. But what you are using in OpenCV with H.264 encoding format. ), the process was getting no results. Maybe you should modify the code of the encoding format of reading video with OpenCV, or there is just no encoder for 'hevc' format in your system, or you can just transform your videos in H.264 encoding format.
@glenn-jocher I think this issues can be closed. @Kylinb is my laboratory brother. : )

@glenn-jocher
Copy link
Member

@JOSHUAWENJZ ok! Yes as you said we use cv2 for video reading, so the videos must be openable by cv2 for YOLOv5 inference to work.

@glenn-jocher glenn-jocher removed the bug Something isn't working label Mar 11, 2021
@JOSHUAWENJZ
Copy link

@glenn-jocher @Kylinb I want to add some advice. Here is a simple solution. Just modify line 134 in detect.py as below.
fps = 25 #enter a fixed number for fps, and it will work.
I think the reason of no result is that OpenCV can't get the frame number and FPS information of your H.265 video. And I got some proof of my think that when I want to get the FPS of H.265 videos, I got 'inf'. @Kylinb Your 'nframes' in datasets.py LoadImages function is negative number. This suggests that OpenCV got wrong information of your H.265 video.

@glenn-jocher
Copy link
Member

@JOSHUAWENJZ so you would recommend hardcoding an FPS in detect.py L134 for better robustness to cv2 property retrieval issues there?

@JOSHUAWENJZ
Copy link

@glenn-jocher Yes. If you know the FPS of input video, just fix fps in detect.py L134. BUT I think there should be a better solution. And I will try to get right FPS and frame number of H.265 video, that is the best solution. : )

@glenn-jocher
Copy link
Member

@JOSHUAWENJZ right, we want a robust solution that swaps in a default FPS on check failures. I don't think we can hard code 25 or 30 because then if someone runs a 60 FPS video for example then the output inference video will play at half speed.

There are a number of checks functions here in general.py, this would probably be the right place for a check_FPS() function. If you'd like to submit a PR for this that would be great!

yolov5/utils/general.py

Lines 55 to 146 in 886f1c0

def check_online():
# Check internet connectivity
import socket
try:
socket.create_connection(("1.1.1.1", 443), 5) # check host accesability
return True
except OSError:
return False
def check_git_status():
# Recommend 'git pull' if code is out of date
print(colorstr('github: '), end='')
try:
assert Path('.git').exists(), 'skipping check (not a git repository)'
assert not isdocker(), 'skipping check (Docker image)'
assert check_online(), 'skipping check (offline)'
cmd = 'git fetch && git config --get remote.origin.url'
url = subprocess.check_output(cmd, shell=True).decode().strip().rstrip('.git') # github repo url
branch = subprocess.check_output('git rev-parse --abbrev-ref HEAD', shell=True).decode().strip() # checked out
n = int(subprocess.check_output(f'git rev-list {branch}..origin/master --count', shell=True)) # commits behind
if n > 0:
s = f"⚠️ WARNING: code is out of date by {n} commit{'s' * (n > 1)}. " \
f"Use 'git pull' to update or 'git clone {url}' to download latest."
else:
s = f'up to date with {url} ✅'
print(s.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else s)
except Exception as e:
print(e)
def check_requirements(file='requirements.txt', exclude=()):
# Check installed dependencies meet requirements
import pkg_resources
requirements = [f'{x.name}{x.specifier}' for x in pkg_resources.parse_requirements(Path(file).open())
if x.name not in exclude]
pkg_resources.require(requirements) # DistributionNotFound or VersionConflict exception if requirements not met
def check_img_size(img_size, s=32):
# Verify img_size is a multiple of stride s
new_size = make_divisible(img_size, int(s)) # ceil gs-multiple
if new_size != img_size:
print('WARNING: --img-size %g must be multiple of max stride %g, updating to %g' % (img_size, s, new_size))
return new_size
def check_imshow():
# Check if environment supports image displays
try:
assert not isdocker(), 'cv2.imshow() is disabled in Docker environments'
cv2.imshow('test', np.zeros((1, 1, 3)))
cv2.waitKey(1)
cv2.destroyAllWindows()
cv2.waitKey(1)
return True
except Exception as e:
print(f'WARNING: Environment does not support cv2.imshow() or PIL Image.show() image displays\n{e}')
return False
def check_file(file):
# Search for file if not found
if os.path.isfile(file) or file == '':
return file
else:
files = glob.glob('./**/' + file, recursive=True) # find file
assert len(files), 'File Not Found: %s' % file # assert file was found
assert len(files) == 1, "Multiple files match '%s', specify exact path: %s" % (file, files) # assert unique
return files[0] # return file
def check_dataset(dict):
# Download dataset if not found locally
val, s = dict.get('val'), dict.get('download')
if val and len(val):
val = [Path(x).resolve() for x in (val if isinstance(val, list) else [val])] # val path
if not all(x.exists() for x in val):
print('\nWARNING: Dataset not found, nonexistent paths: %s' % [str(x) for x in val if not x.exists()])
if s and len(s): # download script
print('Downloading %s ...' % s)
if s.startswith('http') and s.endswith('.zip'): # URL
f = Path(s).name # filename
torch.hub.download_url_to_file(s, f)
r = os.system('unzip -q %s -d ../ && rm %s' % (f, f)) # unzip
else: # bash script
r = os.system(s)
print('Dataset autodownload %s\n' % ('success' if r == 0 else 'failure')) # analyze return value
else:
raise Exception('Dataset not found.')

@riskycheng
Copy link

riskycheng commented Jul 2, 2021

root cause

please check the code line at:
https://github.com/ultralytics/yolov5/blob/9d873077841434d1c6cbd1c4248ca2252820d3ba/utils/general.py#L50
the author is trying to judge whether you are in Docker env by checking whether your absolutepath contains 'workspace':

def isdocker():
    # Is environment a Docker container
    return Path('/workspace').exists()  # or Path('/.dockerenv').exists()

solution:

Ensure there is no 'workspace' word in your full path.

@glenn-jocher
Copy link
Member

glenn-jocher commented Jul 2, 2021

@riskycheng this should only return True if the root directory is called /workspace. If there is a directory for example yolov5/workspace or workspace/yolov5 this will return False.

@riskycheng
Copy link

riskycheng commented Jul 5, 2021

@riskycheng this should only return True if the root directory is called /workspace. If there is a directory for example yolov5/workspace or workspace/yolov5 this will return False.

Hi @glenn-jocher ,
Thanks for correction! You are right and this is correct and clear in linux box, but it is a little bit tricky in windows.
if the path is like : c:/workspace/yolov5/, then it will return True, otherwise it works good since the diskname is actually invisiable for this checking.

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

No branches or pull requests

5 participants