Open jedi008 opened 2 years ago
I am receiving the same issue. When running detect.py it isn't saving anything. I run the following command:
python detect.py --device 0 --weights runs/train/yolov7-xod335/weights/best.pt --conf 0.25 --img-size 416 --source inference/videos/MoogIR-15-11-52_333.mp4 --name xod335-test
And then I receive the following output:
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='0', exist_ok=False, img_size=416, iou_thres=0.45, name='xod335-test', no_trace=False, nosave=False, project='runs/detect', save_conf=False, save_txt=False, source='inference/videos/MoogIR-15-11-52_333.mp4', update=False, view_img=False, weights=['runs/train/yolov7-xod335/weights/best.pt'])
YOLOR 🚀 2022-9-20 torch 1.13.0a0+d321be6 CUDA:0 (NVIDIA GeForce RTX 3080, 10010.0MB)
Fusing layers...
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
IDetect.fuse
/opt/conda/lib/python3.8/site-packages/torch/functional.py:478: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at /opt/pytorch/pytorch/aten/src/ATen/native/TensorShape.cpp:2966.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
Model Summary: 314 layers, 36487166 parameters, 6194944 gradients, 103.2 GFLOPS
Convert model to Traced-model...
traced_script_module saved!
model is traced!
Done. (0.000s)
However, my runs/detect/xod335-test folder is completely empty. Any suggestions?
Same issue
I found out the issue, the PyTorch Docker image that they are using is using an OpenCV that doesn't have Video I/O installed. I found that installing OpenCV with these cleared my issue!
@whittenator awesome, could you elaborate what steps you ran to get the container working for inference on video?
@whittenator Yo big guy I’m also with mkrupczak3 and would love a quick tutorial or set of direction.
I use docker, and this helps me. Thanks whittenator.
pip uninstall opencv-python
pip uninstall opencv-contrib-python
pip install opencv_python==3.4.10.37
@whittenator Yo big guy I’m also with mkrupczak3 and would love a quick tutorial or set of direction.
Sorry for the delay fellas, I had to create a docker image with a custom installation of OpenCV. If you are like me and would like to run inference on your Nvidia GPU then you can use the Docker I created below. Note: Make sure you select the correct arch type for your Nvidia GPU Here is the Docker:
FROM nvcr.io/nvidia/pytorch:22.08-py3
ARG DEBIAN_FRONTEND=noninteractive
ARG OPENCV_VERSION=4.6.0
RUN apt-get update && apt-get upgrade -y &&\
# Install build tools, build dependencies and python
apt-get install -y \
python3-pip \
build-essential \
cmake \
git \
wget \
unzip \
yasm \
pkg-config \
libswscale-dev \
libgtk-3-dev \
libx264-dev \
libtbb2 \
libtbb-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libv4l-dev \
gfortran \
openexr \
libdc1394-22-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer1.0-dev \
libopenexr-dev \
libatlas-base-dev \
libxvidcore-dev \
libavformat-dev \
libpq-dev \
libxine2-dev \
libglew-dev \
libtiff5-dev \
zlib1g-dev \
libavcodec-dev \
libavutil-dev \
libpostproc-dev \
libswscale-dev \
libeigen3-dev \
libtbb-dev \
libgtk2.0-dev \
ffmpeg \
pkg-config \
## Python
python3-dev \
python3-numpy \
python3-magic \
zip \
htop \
screen \
libgl1-mesa-glx \
&& rm -rf /var/lib/apt/lists/*
# Install all Video I/O and OpenCV Dependencies
RUN apt-get install -y \
build-essential cmake git pkg-config libgtk-3-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \
gfortran openexr libatlas-base-dev python3-dev python3-numpy \
libtbb2 libtbb-dev libdc1394-22-dev libopenexr-dev \
libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
RUN cd /opt/ &&\
# Download and unzip OpenCV and opencv_contrib and delte zip files
wget https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip &&\
unzip $OPENCV_VERSION.zip &&\
rm $OPENCV_VERSION.zip &&\
wget https://github.com/opencv/opencv_contrib/archive/$OPENCV_VERSION.zip &&\
unzip ${OPENCV_VERSION}.zip &&\
rm ${OPENCV_VERSION}.zip &&\
# Create build folder and switch to it
mkdir /opt/opencv-${OPENCV_VERSION}/build && cd /opt/opencv-${OPENCV_VERSION}/build &&\
# Cmake configure
cmake \
-DOPENCV_EXTRA_MODULES_PATH=/opt/opencv_contrib-${OPENCV_VERSION}/modules \
-DWITH_CUDA=ON \
-DCUDA_GENERATION=Auto \
-DWITH_CUDNN=ON \
-DWITH_CUBLAS=ON \
-DWITH_TBB=ON \
-DOPENCV_DNN_CUDA=ON \
-DOPENCV_ENABLE_NONFREE=ON \
-DCUDA_ARCH_BIN=7.5,8.0,8.6 \
-DWITH_FFMPEG=ON
-DWITH_GSTREAMER=ON
-D HAVE_opencv_python3=ON \
-DCMAKE_BUILD_TYPE=RELEASE \
# Install path will be /usr/local/lib (lib is implicit)
-DCMAKE_INSTALL_PREFIX=/usr/local \
.. &&\
# Make
make -j"$(nproc)" && \
# Install to /usr/local/lib
make install && \
ldconfig &&\
# Remove OpenCV sources and build folder
rm -rf /opt/opencv-${OPENCV_VERSION} && rm -rf /opt/opencv_contrib-${OPENCV_VERSION}
# Install python dependencies
RUN pip install seaborn thop nvidia-pyindex nvidia-tensorrt pycuda
# The YoloV7 training repo
RUN git clone https://github.com/WongKinYiu/yolov7.git
# Clone repo that allows conversion of pytorch to TensorRT with NMS
RUN git clone https://github.com/Linaom1214/tensorrt-python.git
Hope this helps!
OS: windows10 GPU: NVIDIA GeForce MX450 Command: python detect.py Weights: https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt and yolov7x.pt Output: didn't detect any object.
The reason is that pred is an invalid value: https://github.com/WongKinYiu/yolov7/blob/55b90e111984dd85e7eed327e9ff271222aa8b82/detect.py#L87 pred is [nan, nan, nan, ..., nan, nan, nan].
Change this line to: half = False https://github.com/WongKinYiu/yolov7/blob/55b90e111984dd85e7eed327e9ff271222aa8b82/detect.py#L31 Then got the right result.