Skip to content

Commit

Permalink
matplotlib installation
Browse files Browse the repository at this point in the history
  • Loading branch information
bertoni9 committed May 17, 2021
1 parent c9f8c9c commit 9254d15
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ For quick installation, do not clone this repository, make sure there is no fold

```
pip3 install monoloco
pip3 install matplotlib
```

For development of the source code itself, you need to clone this repository and then:
Expand Down Expand Up @@ -186,6 +187,10 @@ An example from the Collective Activity Dataset is provided below.

To visualize social distancing run the below, command:

```sh
pip install scipy
```

```sh
python -m monoloco.run predict docs/frame0032.jpg \
--activities social_distance --output_types front bird
Expand All @@ -196,6 +201,10 @@ python -m monoloco.run predict docs/frame0032.jpg \
## C) Hand-raising detection
To detect raised hand, you can add the argument `--activities raise_hand` to the prediction command.

For example, the below image is obtained with:
```sh
python -m monoloco.run predict --activities raise_hand social_distance output_types front
```

<img src="docs/out_raising_hand.jpg.front.jpg" width="500"/>

Expand Down
10 changes: 9 additions & 1 deletion monoloco/train/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
import time
from itertools import chain

import matplotlib.pyplot as plt
try:
import matplotlib.pyplot as plt
except ImportError:
plt = None

import torch
from torch.utils.data import DataLoader
from torch.optim import lr_scheduler
Expand Down Expand Up @@ -328,6 +332,10 @@ def _print_losses(self, epoch_losses):
if not self.print_loss:
return
os.makedirs(self.dir_figures, exist_ok=True)

if plt is None:
raise Exception('please install matplotlib')

for idx, phase in enumerate(epoch_losses):
for idx_2, el in enumerate(epoch_losses['train']):
plt.figure(idx + idx_2)
Expand Down
17 changes: 9 additions & 8 deletions monoloco/visuals/pifpaf_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
import numpy as np
from PIL import Image

try:
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.patches import Circle, FancyArrow
import scipy.ndimage as ndimage
except ImportError:
ndimage = None
plt = None

import matplotlib
import matplotlib.pyplot as plt
from matplotlib.patches import Circle, FancyArrow
import scipy.ndimage as ndimage


COCO_PERSON_SKELETON = [
Expand Down Expand Up @@ -49,6 +46,10 @@ def image_canvas(image, fig_file=None, show=True, dpi_factor=1.0, fig_width=10.0
if 'figsize' not in kwargs:
kwargs['figsize'] = (fig_width, fig_width * image.size[1] / image.size[0])

if plt is None:
raise Exception('please install matplotlib')
if ndimage is None:
raise Exception('please install scipy')
fig = plt.figure(**kwargs)
ax = plt.Axes(fig, [0.0, 0.0, 1.0, 1.0])
ax.set_axis_off()
Expand Down
2 changes: 1 addition & 1 deletion monoloco/visuals/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def image_attributes(dpi, output_types):
mono=dict(color='red',
numcolor='firebrick',
linewidth=2 * c)
)
)


class Printer:
Expand Down

0 comments on commit 9254d15

Please sign in to comment.