forked from lanpa/tensorboardX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes for Caffe2 and tests to switch over to lanpa/tensorboardX (lanp…
…a#259) * Fix caffe2_graph to match latest PyTorch/Caffe2 master * Use unittest classes for tests * Fix some issues with Caffe2 writer and improve tests
- Loading branch information
Showing
9 changed files
with
171 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,51 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import matplotlib.pyplot as plt | ||
from tensorboardX import SummaryWriter | ||
import unittest | ||
|
||
from tensorboardX import SummaryWriter | ||
|
||
def test_figure(): | ||
writer = SummaryWriter() | ||
|
||
figure, axes = plt.figure(), plt.gca() | ||
circle1 = plt.Circle((0.2, 0.5), 0.2, color='r') | ||
circle2 = plt.Circle((0.8, 0.5), 0.2, color='g') | ||
axes.add_patch(circle1) | ||
axes.add_patch(circle2) | ||
plt.axis('scaled') | ||
plt.tight_layout() | ||
class FigureTest(unittest.TestCase): | ||
def test_figure(self): | ||
writer = SummaryWriter() | ||
|
||
writer.add_figure("add_figure/figure", figure, 0, close=False) | ||
assert plt.fignum_exists(figure.number) is True | ||
figure, axes = plt.figure(), plt.gca() | ||
circle1 = plt.Circle((0.2, 0.5), 0.2, color='r') | ||
circle2 = plt.Circle((0.8, 0.5), 0.2, color='g') | ||
axes.add_patch(circle1) | ||
axes.add_patch(circle2) | ||
plt.axis('scaled') | ||
plt.tight_layout() | ||
|
||
writer.add_figure("add_figure/figure", figure, 1) | ||
assert plt.fignum_exists(figure.number) is False | ||
writer.add_figure("add_figure/figure", figure, 0, close=False) | ||
assert plt.fignum_exists(figure.number) is True | ||
|
||
writer.close() | ||
writer.add_figure("add_figure/figure", figure, 1) | ||
assert plt.fignum_exists(figure.number) is False | ||
|
||
writer.close() | ||
|
||
def test_figure_list(): | ||
writer = SummaryWriter() | ||
def test_figure_list(self): | ||
writer = SummaryWriter() | ||
|
||
figures = [] | ||
for i in range(5): | ||
figure = plt.figure() | ||
plt.plot([i * 1, i * 2, i * 3], label="Plot " + str(i)) | ||
plt.xlabel("X") | ||
plt.xlabel("Y") | ||
plt.legend() | ||
plt.tight_layout() | ||
figures.append(figure) | ||
figures = [] | ||
for i in range(5): | ||
figure = plt.figure() | ||
plt.plot([i * 1, i * 2, i * 3], label="Plot " + str(i)) | ||
plt.xlabel("X") | ||
plt.xlabel("Y") | ||
plt.legend() | ||
plt.tight_layout() | ||
figures.append(figure) | ||
|
||
writer.add_figure("add_figure/figure_list", figures, 0, close=False) | ||
assert all([plt.fignum_exists(figure.number) is True for figure in figures]) | ||
writer.add_figure("add_figure/figure_list", figures, 0, close=False) | ||
assert all([plt.fignum_exists(figure.number) is True for figure in figures]) | ||
|
||
writer.add_figure("add_figure/figure_list", figures, 1) | ||
assert all([plt.fignum_exists(figure.number) is False for figure in figures]) | ||
writer.add_figure("add_figure/figure_list", figures, 1) | ||
assert all([plt.fignum_exists(figure.number) is False for figure in figures]) | ||
|
||
writer.close() | ||
writer.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
from tensorboardX import x2num | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import numpy as np | ||
import unittest | ||
|
||
from tensorboardX import x2num | ||
|
||
def test_scalar(): | ||
res = x2num.make_np(1.1) | ||
assert isinstance(res, np.ndarray) and res.shape == (1,) | ||
res = x2num.make_np(1000000000000000000000) | ||
assert isinstance(res, np.ndarray) and res.shape == (1,) | ||
res = x2num.make_np(np.float16(1.00000087)) | ||
assert isinstance(res, np.ndarray) and res.shape == (1,) | ||
res = x2num.make_np(np.float128(1.00008 + 9)) | ||
assert isinstance(res, np.ndarray) and res.shape == (1,) | ||
res = x2num.make_np(np.int64(100000000000)) | ||
assert isinstance(res, np.ndarray) and res.shape == (1,) | ||
|
||
class NumpyTest(unittest.TestCase): | ||
def test_scalar(self): | ||
res = x2num.make_np(1.1) | ||
assert isinstance(res, np.ndarray) and res.shape == (1,) | ||
res = x2num.make_np(1000000000000000000000) | ||
assert isinstance(res, np.ndarray) and res.shape == (1,) | ||
res = x2num.make_np(np.float16(1.00000087)) | ||
assert isinstance(res, np.ndarray) and res.shape == (1,) | ||
res = x2num.make_np(np.float128(1.00008 + 9)) | ||
assert isinstance(res, np.ndarray) and res.shape == (1,) | ||
res = x2num.make_np(np.int64(100000000000)) | ||
assert isinstance(res, np.ndarray) and res.shape == (1,) | ||
|
||
def test_make_grid(): | ||
pass | ||
def test_make_grid(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,42 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
from tensorboardX import x2num, SummaryWriter | ||
import torch | ||
import numpy as np | ||
tensors = [torch.rand(3, 10, 10), torch.rand(1), torch.rand(1, 2, 3, 4, 5)] | ||
|
||
|
||
def test_pytorch_np(): | ||
for tensor in tensors: | ||
# regular tensor | ||
assert isinstance(x2num.make_np(tensor), np.ndarray) | ||
import unittest | ||
|
||
# CUDA tensor | ||
if torch.cuda.device_count() > 0: | ||
assert isinstance(x2num.make_np(tensor.cuda()), np.ndarray) | ||
|
||
# regular variable | ||
assert isinstance(x2num.make_np(torch.autograd.Variable(tensor)), np.ndarray) | ||
class PyTorchNumpyTest(unittest.TestCase): | ||
def test_pytorch_np(self): | ||
tensors = [torch.rand(3, 10, 10), torch.rand(1), torch.rand(1, 2, 3, 4, 5)] | ||
for tensor in tensors: | ||
# regular tensor | ||
assert isinstance(x2num.make_np(tensor), np.ndarray) | ||
|
||
# CUDA variable | ||
if torch.cuda.device_count() > 0: | ||
assert isinstance(x2num.make_np(torch.autograd.Variable(tensor).cuda()), np.ndarray) | ||
# CUDA tensor | ||
if torch.cuda.device_count() > 0: | ||
assert isinstance(x2num.make_np(tensor.cuda()), np.ndarray) | ||
|
||
# python primitive type | ||
assert(isinstance(x2num.make_np(0), np.ndarray)) | ||
assert(isinstance(x2num.make_np(0.1), np.ndarray)) | ||
# regular variable | ||
assert isinstance(x2num.make_np(torch.autograd.Variable(tensor)), np.ndarray) | ||
|
||
# CUDA variable | ||
if torch.cuda.device_count() > 0: | ||
assert isinstance(x2num.make_np(torch.autograd.Variable(tensor).cuda()), np.ndarray) | ||
|
||
def test_pytorch_img(): | ||
shapes = [(77, 3, 13, 7), (77, 1, 13, 7), (3, 13, 7), (1, 13, 7), (13, 7)] | ||
for s in shapes: | ||
x = torch.Tensor(np.random.random_sample(s)) | ||
assert x2num.make_np(x, 'IMG').shape[2] == 3 | ||
# python primitive type | ||
assert(isinstance(x2num.make_np(0), np.ndarray)) | ||
assert(isinstance(x2num.make_np(0.1), np.ndarray)) | ||
|
||
def test_pytorch_img(self): | ||
shapes = [(77, 3, 13, 7), (77, 1, 13, 7), (3, 13, 7), (1, 13, 7), (13, 7)] | ||
for s in shapes: | ||
x = torch.Tensor(np.random.random_sample(s)) | ||
assert x2num.make_np(x, 'IMG').shape[2] == 3 | ||
|
||
def test_pytorch_write(): | ||
with SummaryWriter() as w: | ||
w.add_scalar('scalar', torch.autograd.Variable(torch.rand(1)), 0) | ||
def test_pytorch_write(self): | ||
with SummaryWriter() as w: | ||
w.add_scalar('scalar', torch.autograd.Variable(torch.rand(1)), 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.