From 9254d15e8e3fc3db0d1a4b8bc2cfb02303ff47d9 Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Mon, 17 May 2021 10:17:27 +0200 Subject: [PATCH] matplotlib installation --- README.md | 9 +++++++++ monoloco/train/trainer.py | 10 +++++++++- monoloco/visuals/pifpaf_show.py | 17 +++++++++-------- monoloco/visuals/printer.py | 2 +- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b1a1cf65..ca434816 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/monoloco/train/trainer.py b/monoloco/train/trainer.py index 079d90c1..d0e32ba9 100644 --- a/monoloco/train/trainer.py +++ b/monoloco/train/trainer.py @@ -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 @@ -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) diff --git a/monoloco/visuals/pifpaf_show.py b/monoloco/visuals/pifpaf_show.py index 46bc4dcd..427de5be 100644 --- a/monoloco/visuals/pifpaf_show.py +++ b/monoloco/visuals/pifpaf_show.py @@ -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 = [ @@ -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() diff --git a/monoloco/visuals/printer.py b/monoloco/visuals/printer.py index 7a552d17..6ce0b88f 100644 --- a/monoloco/visuals/printer.py +++ b/monoloco/visuals/printer.py @@ -37,7 +37,7 @@ def image_attributes(dpi, output_types): mono=dict(color='red', numcolor='firebrick', linewidth=2 * c) - ) + ) class Printer: