Skip to content

Commit

Permalink
Merge pull request #976 from vilyaair/Agg
Browse files Browse the repository at this point in the history
Avoid to import matplotlib to set its backend Agg in code like chainer
  • Loading branch information
okuta committed Mar 23, 2018
1 parent 58fe039 commit 4bd2901
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
19 changes: 19 additions & 0 deletions examples/gmm/README.md
@@ -0,0 +1,19 @@
# GMM example

This example contains implementation of Gaussian Mixture Model (GMM).


### How to demo
The demo contains a script that partitions data into groups using Gaussian Mixture Model.
The demo can be run by the following command.

```
python gmm.py [--gpu-id GPU_ID] [--num NUM] [--dim DIM]
[--max-iter MAX_ITER] [--tol TOL] [--output-image OUTPUT]
```

If you run this script on environment without matplotlib renderers (e.g., non-GUI environment), setting the environmental variable `MPLBACKEND` to `Agg` may be required to use `matplotlib`. For example,

```
MPLBACKEND=Agg python gmm.py ...
```
2 changes: 0 additions & 2 deletions examples/gmm/gmm.py
Expand Up @@ -2,8 +2,6 @@
import contextlib
import time

import matplotlib
matplotlib.use('Agg')
from matplotlib import mlab
import matplotlib.pyplot as plt
import numpy as np
Expand Down
20 changes: 20 additions & 0 deletions examples/kmeans/README.md
@@ -0,0 +1,20 @@
# kmeans example

This example contains implementation of K-means clustering.


### How to demo
The demo contains a script that partitions data into groups using K-means clustering.
The demo can be run by the following command.

```
python kmeans.py [--gpu-id GPU_ID] [--n-clusters N_CLUSTERS] [--num NUM]
[--max-iter MAX_ITER] [--use-custom-kernel]
[--output-image OUTPUT_IMAGE]
```

If you run this script on environment without matplotlib renderers (e.g., non-GUI environment), setting the environmental variable `MPLBACKEND` to `Agg` may be required to use `matplotlib`. For example,

```
MPLBACKEND=Agg python kmeans.py ...
```
2 changes: 0 additions & 2 deletions examples/kmeans/kmeans.py
Expand Up @@ -2,8 +2,6 @@
import contextlib
import time

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import six
Expand Down
3 changes: 3 additions & 0 deletions tests/example_tests/test_gmm.py
Expand Up @@ -10,6 +10,9 @@
from example_tests import example_test


os.environ['MPLBACKEND'] = 'Agg'


@testing.with_requires('matplotlib')
class TestGMM(unittest.TestCase):

Expand Down
3 changes: 3 additions & 0 deletions tests/example_tests/test_kmeans.py
Expand Up @@ -10,6 +10,9 @@
from example_tests import example_test


os.environ['MPLBACKEND'] = 'Agg'


@testing.with_requires('matplotlib')
class TestKmeans(unittest.TestCase):

Expand Down

0 comments on commit 4bd2901

Please sign in to comment.