matplotlib installation

This commit is contained in:
Lorenzo 2021-05-17 10:17:27 +02:00
parent c9f8c9c850
commit 9254d15e8e
4 changed files with 28 additions and 10 deletions

View File

@ -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:
@ -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
@ -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"/>

View File

@ -16,7 +16,11 @@ import sys
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
@ -328,6 +332,10 @@ class Trainer:
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)

View File

@ -11,14 +11,11 @@ import math
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 = [
@ -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()

View File

@ -37,7 +37,7 @@ def image_attributes(dpi, output_types):
mono=dict(color='red',
numcolor='firebrick',
linewidth=2 * c)
)
)
class Printer: