Skip to content

Commit

Permalink
DockerPy and some error corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
aagustinconti committed Apr 14, 2023
1 parent 73be9b1 commit e843f85
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 303 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.pt
*.avi
*.mp4
*.jpg

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
29 changes: 10 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ In addition to the detections, **it has been possible to track these objects and

### Information flow

![Information flow](readme-img/Untitled.png)
![Information flow](readme-img/graph_1.png)

### Count algorithm

![Count Algorithm](readme-img/Untitled%201.png)
![Count Algorithm](readme-img/graph_2.png)

## Results

Expand Down Expand Up @@ -105,7 +105,7 @@ Do this following steps *in order.*
nvtop # To run the nvtop
```

![nvidia-smi](/readme-img/Untitled%202.png)
![nvidia-smi](/readme-img/nvidia-smi.png)

**Pull nvidia-gpu image**

Expand All @@ -117,26 +117,14 @@ Follow this **[installation guide.](https://docs.nvidia.com/datacenter/cloud-na
git pull https://github.com/aagustinconti/yolov7_counting
```

**Change permissions of ./start.sh**

```bash
sudo chmod +x ./start.sh
```

**Download YOLOv7x pretrained weights**

1. Download the pretrained weights of YOLOv7x [here.](https://github.com/WongKinYiu/yolov7/blob/main/README.md#performance)
2. Save them in **./pretrained_weights** directory.

**RUN ./start.sh**

To build the docker image if is not available in your PC and run the container with the propp

```bash
./start.sh
```

### Configuring the test
**Configuring the test**

- Into the **test_oop.py** file you can modify some characteristics of the instance of the class *YoloSortCount()* before to execute the *run()* method.
- By default:
Expand All @@ -145,15 +133,18 @@ To build the docker image if is not available in your PC and run the container w
- Classes: person (ID: 0)
- Save: False

**RUN the test**

On the docker terminal run
**RUN docker_control.py**

To build the docker image if it's not available in your PC and run the container with the propp
```bash
python test_oop.py
python3 docker_control.py
```
## Thanks to
[YOLOv7](https://github.com/WongKinYiu/yolov7/)
Expand Down
5 changes: 3 additions & 2 deletions dependencies/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Specify the parent image from which we build
FROM pytorch/pytorch:latest
FROM pytorch/pytorch:1.13.1-cuda11.6-cudnn8-runtime

# Copy the dependencies directory
COPY . /dependencies_files_docker
Expand All @@ -11,7 +11,8 @@ WORKDIR /dependencies_files_docker
RUN pip install -r requirements.txt
RUN chmod +x dependencies.sh
RUN bash dependencies.sh
RUN cp -f ./upsampling.py /opt/conda/lib/python3.7/site-packages/torch/nn/modules/upsampling.py
RUN mv /opt/conda/lib/python3.10/site-packages/torch/nn/modules/upsampling.py /opt/conda/lib/python3.10/site-packages/torch/nn/modules/upsampling_wrong.py
RUN cp -f ./upsampling.py /opt/conda/lib/python3.10/site-packages/torch/nn/modules/upsampling.py

# To go to the working directory
WORKDIR /workspace
Expand Down
36 changes: 18 additions & 18 deletions dependencies/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
opencv-python==4.6.0.66
scipy==1.7.3
gdown==4.5.3
tensorboard==2.10.1
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
pafy==0.5.5
youtube-dl==2020.12.2
pandas==1.3.5


absl-py==1.3.0
brotlipy==0.7.0
cachetools==5.2.0
conda==4.13.0
conda-build==3.21.9
cycler==0.11.0
Cython==0.29.32
deep-sort-realtime==1.3.1
dnspython==2.2.1
easydict==1.10
flake8==5.0.4
fonttools==4.37.4
future==0.18.2
gdown==4.5.3

google-auth==2.13.0
google-auth-oauthlib==0.4.6
grpcio==1.50.0
Expand All @@ -32,36 +40,28 @@ nvidia-cuda-nvrtc-cu11==11.7.99
nvidia-cuda-runtime-cu11==11.7.99
nvidia-cudnn-cu11==8.5.0.96
oauthlib==3.2.2
opencv-python==4.6.0.66

packaging==21.3
pafy==0.5.5
pandas==1.3.5


Pillow==9.0.1
protobuf==3.19.6
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycodestyle==2.9.1
pycosat==0.6.3
pyflakes==2.5.0
pyparsing==3.0.9
python-dateutil==2.8.2
python-etcd==0.4.5
PyYAML==6.0
requests-oauthlib==1.3.1
rsa==4.9
scipy==1.7.3

seaborn==0.12.0
tb-nightly==2.11.0a20221105
tensorboard==2.10.1
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
thop==0.1.1.post2209072238
torch==1.13.0
torchelastic==0.2.0
torchtext==0.13.0
torchvision==0.14.0

Werkzeug==2.2.2
yacs==0.1.8
yapf==0.32.0
youtube-dl==2020.12.2

zipp==3.10.0
5 changes: 3 additions & 2 deletions dependencies/upsampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ def __init__(self, size: Optional[_size_any_t] = None, scale_factor: Optional[_r
self.recompute_scale_factor = recompute_scale_factor

def forward(self, input: Tensor) -> Tensor:
return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners)
#recompute_scale_factor=self.recompute_scale_factor)
return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners,
#recompute_scale_factor=self.recompute_scale_factor
)

def extra_repr(self) -> str:
if self.scale_factor is not None:
Expand Down
20 changes: 16 additions & 4 deletions docker_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@

logging.info("Checking if the Image already exists...")

if not os.system('[ "$(docker image inspect yolov7_detect_track_count:latest 2> /dev/null)" == [] ]'):
if str(os.popen("docker image inspect yolov7_detect_track_count:latest 2> /dev/null").read())[:2] == "[]":

logging.info("The image doesn't exist. Building the Docker Image...")

os.system("cd ./dependencies")
os.chdir("./dependencies")

cwd = os.getcwd()
logging.info(f"The current directory is --> {cwd}")

os.system("docker build -t yolov7_detect_track_count .")
os.system("cd ..")
os.chdir("..")

cwd = os.getcwd()
logging.info(f"The current directory is --> {cwd}")

else:
logging.info("The image has already exists.")
Expand All @@ -41,9 +48,15 @@


logging.info("Running a container...")


container = client.containers.run(
image='yolov7_detect_track_count:latest',
stdin_open=True,
tty=True,
auto_remove=True,
network_mode='host',
name="test",
device_requests=[docker.types.DeviceRequest(
device_ids=["0"], capabilities=[['gpu']])],
devices=["/dev/video0:/dev/video0"],
Expand All @@ -52,6 +65,5 @@
cwd: {'bind': '/workspace', 'mode': 'rw'}
},
environment=[f"DISPLAY={display}"],
tty=True,
command='python test_oop.py'
)
38 changes: 0 additions & 38 deletions flask-app.py

This file was deleted.

File renamed without changes
File renamed without changes
File renamed without changes
28 changes: 0 additions & 28 deletions start.sh

This file was deleted.

10 changes: 0 additions & 10 deletions templates/index.html

This file was deleted.

10 changes: 5 additions & 5 deletions test_oop.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
WebCamera: 0 ---> DEFAULT
Youtube Video or stream: "https://www.youtube.com/watch?v=qP1y7Tdab7Y"
Stream URL: "http://IP/hls/stream_src.m3u8"
RSTP Stream: "http://192.168.102.3:4747/video"
RSTP Stream: "http://192.168.1.3:4747/video"
Local video: "img_bank/cows_for_sale.mp4"
Local image: "img_bank/img.jpg" | "img_bank/img.png"
"""
test.video_path = 0 #"http://192.168.102.3:4747/video"
test.video_path = 0#"https://www.youtube.com/watch?v=2wqpy036z24"


"""
Expand All @@ -28,7 +28,7 @@
"""
test.max_width = 720
test.max_fps = 25 # Max 1000
test.inv_h_frame = False
test.inv_h_frame = True


"""
Expand All @@ -51,7 +51,7 @@
- Load the ROI color.
"""
#test.roi = [0,0,0,0]
test.auto_load_roi = False
test.auto_load_roi = True
test.roi_color = (255, 255, 255)


Expand All @@ -68,7 +68,7 @@
"""
test.model_path = 'pretrained_weights/yolov7.pt'
test.graphic_card = 0
test.class_ids = []
test.class_ids = [0]
test.img_sz = 640
test.color = (0, 255, 0)
test.conf_thres = 0.5
Expand Down
Loading

0 comments on commit e843f85

Please sign in to comment.