---
title: "(Draft) Ubuntu, Jupyter Notebook, Python3, Tensorflow, OpenCV : Comptage des cyclistes"
url: https://www.cyber-neurones.org/2020/10/draft-ubuntu-jupyter-notebook-python3-tensorflow-opencv-comptage-des-cyclistes/
date: 2020-10-05
modified: 2020-10-05
author: "Frederic"
description: "J'ai essayé un nouveau projet sur Github pour le comptage des cyclistes : https://github.com/ahmetozlu/tensorflow_object_counting_api . J'ai du modifier le code pour utiliser TensorFlow : 2.3.1  . - tf.GraphDef => tf.compat.v1.GraphDef..."
categories:
  - "Ubuntu"
word_count: 266
---

# (Draft) Ubuntu, Jupyter Notebook, Python3, Tensorflow, OpenCV : Comptage des cyclistes

J'ai essayé un nouveau projet sur Github pour le comptage des cyclistes : [https://github.com/ahmetozlu/tensorflow_object_counting_api](https://github.com/ahmetozlu/tensorflow_object_counting_api) .

J'ai du modifier le code pour utiliser **TensorFlow** : 2.3.1  .

- tf.GraphDef => tf.**compat.v1.**GraphDef
- tf.gfile.GFile => tf.**compat.v2.io.**gfile.GFile
- tf.Session => tf.**compat.v1.**Session
Ensuite j'ai du adapter le programme à ma vidéo, j'ai adapté les programmes : **vehicle_counting.py** & **real_time_couting_target_object.py** . Le but était de positionner la ligne de comptage par rapport à la dimension de ma vidéo ( roi = 900 / 1280 ).

Avec **real_time_couting_target_object.py (modifié)** : ( c'est la le top quand on compte 10 cyclistes, il en compte 2 ... Misère)
[![](https://www.cyber-neurones.org/wp-content/uploads/2020/10/screenshot-from-2020-10-05-08-39-55-300x179.png)](https://www.cyber-neurones.org/wp-content/uploads/2020/10/screenshot-from-2020-10-05-08-39-55.png)

Avec **vehicle_counting.py (modifié)** , sur 120 cyclistes seulement 42 sont comptés:

[![](https://www.cyber-neurones.org/wp-content/uploads/2020/10/capture-decran-2020-10-05-a-11-24-40-1024x616.png)](https://www.cyber-neurones.org/wp-content/uploads/2020/10/capture-decran-2020-10-05-a-11-24-40.png) [![](https://www.cyber-neurones.org/wp-content/uploads/2020/10/capture-decran-2020-10-05-a-11-24-58-300x169.png)](https://www.cyber-neurones.org/wp-content/uploads/2020/10/capture-decran-2020-10-05-a-11-24-58.png)

Ma vidéo source fait ( GoPro ):

- Dimenssion 1280 x 720
- Codec H.264
- 24 frames/sec
- Bitrate 6810 kps
- Durée 1min 51 sec.
- Taille 95 Mo.

A suivre ...

A noter que le modèle utilisé c'est "ssd_mobilenet_v1_coco_**2018**_01_28" et 'mscoco_label_map.pbtxt' . ( sur [http://download.tensorflow.org/models/object_detection/](http://download.tensorflow.org/models/object_detection/) ) . Je pense qu'il y a une version 2019 : [https://arxiv.org/abs/1801.04381 ](https://arxiv.org/abs/1801.04381)& [https://github.com/tensorflow/models/tree/master/research/slim/nets/mobilenet ](https://github.com/tensorflow/models/tree/master/research/slim/nets/mobilenet) . Le nom doit être `ssd_mobilenet_v3_small_coco_2019_08_14 .`

### UPDATE avec la version backbone.set_model('ssd_mobilenet_v3_small_coco_2019_08_14', 'mscoco_label_map.pbtxt') :

J'ai du modifier dans** api/object_counting_api.py**
with tf.compat.v1.Session(graph=detection_graph) as sess:
# Definite input and output Tensors for detection_graph
#image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
**image_tensor = 'image_tensor:0'**

# Each box represents a part of the image where a particular object was detected.
#detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
**detection_boxes = 'detection_boxes:0'**

# Each score represent how level of confidence for each of the objects.
# Score is shown on the result image, together with the class label.
#detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
#detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
#num_detections = detection_graph.get_tensor_by_name('num_detections:0')
**detection_scores = 'detection_scores:0'**
**detection_classes = 'detection_classes:0'**
**num_detections = 'num_detections:0'**