Simple wrapper code to run inference on images using the model and code from the Looking Repo from VITA-EPFL.
Project description
LOOK: A Wrapper For A Visual Attention Model
Simple wrapper code to run inference on images using the model and code from the Looking Repo from VITA-EPFL.
The Looking Repo is an official implementation of the paper Do pedestrians pay attention? Eye contact detection for autonomous driving
Image taken from : https://jooinn.com/people-walking-on-pedestrian-lane-during-daytime.html . Results obtained with the model trained on JackRabbot, Nuscenes, JAAD and Kitti. The model file is available at models/predictor and can be reused for testing with the predictor.
Table of contents
Requirements
pip install python-look
Use 3.6.9 <= python < 3.9. Run pip3 install -r requirements.txt to get the dependencies
PLEASE DOWNLOAD THE MODEL HERE AND PLACE IN THE SAME LOCATION(or name the location when create the instance of the class)
Custom Training And Model Evaluation
Please refer to the original repo for training custom models and evaluation of models.
Predictor
Get predictions from the pretrained model using any image with the predictor API. The API extracts the human keypoints on the fly using OpenPifPaf. The predictor supports eye contact detection using human keypoints only.
Run Inference
- Create an instance of the Predictor (with default or custom settings)
import look
pred = look.Predictor()
pred.predict(image)
output_image = pred.get_output_image()
Predictor Initialization Parameters
| Parameter | Default Value | Description |
|---|---|---|
transparency |
0.4 |
transparency of the overlayed poses float |
looking_threshold |
0.5 |
eye contact threshold float |
mode |
joints |
prediction mode string |
device |
'0' |
CUDA device string |
pifpaf_ver |
shufflenetv2k30 |
PIFPAF ARG: backbone model to use string |
model_path |
models/predictor |
To use custom trained model string |
batch_size |
1 |
PIFPAF ARG: processing batch size int |
long_edge |
None |
PIFPAF ARG: rescale the long side of the image (aspect ratio maintained) int |
loader_workers |
None |
PIFPAF ARG: number of workers for data loading int |
disable_cuda |
False |
PIFPAF ARG: disable CUDA bool |
Example Code To Run:
import cv2
import look
pred = look.Predictor()
cap = cv2.VideoCapture(0)
if cap.isOpened() == False:
print("Camera feed is not open")
exit()
width = int(cap.get(3))
height = int(cap.get(4))
print(f'Image Size: {width} X {height}')
while True:
ret, frame = cap.read()
if ret == True:
pred.predict(frame)
frame = pred.get_output_image()
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
print('Could not get frame from video')
break
cap.release()
cv2.destroyAllWindows()
Credits
Credits to OpenPifPaf for the pose detection part.
Cite VITA-EPFL's work
If you use our work for your research please cite VITA-EPFL :)
@misc{belkada2021pedestrians,
title={Do Pedestrians Pay Attention? Eye Contact Detection in the Wild},
author={Younes Belkada and Lorenzo Bertoni and Romain Caristan and Taylor Mordan and Alexandre Alahi},
year={2021},
eprint={2112.04212},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python-look-0.1.0.tar.gz.
File metadata
- Download URL: python-look-0.1.0.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7acedc4c210b64c170ee6fd86b183df483a20e5b3a681a664b7d0928bbf1781
|
|
| MD5 |
ddcff845d678fe64c739d52c885cb4b2
|
|
| BLAKE2b-256 |
a544b9ef37ed39e4aee451f45ce4764a410acb86cba12903f06fa025e6b7da7c
|
File details
Details for the file python_look-0.1.0-py3-none-any.whl.
File metadata
- Download URL: python_look-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6dedd720ad4cad336418c40512a1096e3ddec59bd8fd61ed10e4b09e3aba734
|
|
| MD5 |
a21d51c0560900b4bd8fd1de8ea75f0d
|
|
| BLAKE2b-256 |
9cd7d09a53bc7bef7ad9a400c94c70d6b4405094cd1a9992388961000d052677
|