Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_summary.py 4.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
  1. import pytest
  2. import matplotlib
  3. matplotlib.use("Agg")
  4. from wandb.summary import FileSummary
  5. from click.testing import CliRunner
  6. from wandb import Histogram, Image, Graph, Table
  7. import matplotlib.pyplot as plt
  8. import plotly.graph_objs as go
  9. import numpy as np
  10. import os
  11. import glob
  12. import json
  13. import torch
  14. import tensorflow as tf
  15. import pandas as pd
  16. @pytest.fixture
  17. def summary():
  18. with CliRunner().isolated_filesystem():
  19. s = FileSummary()
  20. s.update({"foo": "init"})
  21. yield s
  22. def disk_summary():
  23. return json.load(open("wandb-summary.json"))
  24. def test_set_attrs(summary):
  25. summary.foo = "bar"
  26. assert disk_summary() == {"foo": "bar"}
  27. def test_get_attr(summary):
  28. assert summary.foo == "init"
  29. def test_update(summary):
  30. summary.update({"foo": "bar"})
  31. assert disk_summary() == {"foo": "bar"}
  32. def test_update_histogram(summary):
  33. summary.update({"hist": Histogram(np_histogram=([1, 2, 3], [1, 2, 3, 4]))})
  34. assert disk_summary() == {
  35. 'foo': 'init',
  36. "hist": {"_type": "histogram", "values": [1, 2, 3], "bins": [1, 2, 3, 4]}}
  37. def test_set_histogram(summary):
  38. summary["hist"] = Histogram(np_histogram=([1, 2, 3], [1, 2, 3, 4]))
  39. assert disk_summary() == {
  40. 'foo': 'init',
  41. "hist": {"_type": "histogram", "values": [1, 2, 3], "bins": [1, 2, 3, 4]}}
  42. def test_set_item(summary):
  43. summary["foo"] = "bar"
  44. assert disk_summary() == {"foo": "bar"}
  45. def test_get_item(summary):
  46. assert summary["foo"] == "init"
  47. def test_delete(summary):
  48. summary.update({"foo": "bar", "bad": True})
  49. del summary["bad"]
  50. assert disk_summary() == {"foo": "bar"}
  51. def test_image(summary):
  52. summary["image"] = Image(np.random.rand(28, 28))
  53. assert disk_summary()['image'] == {
  54. '_type': 'images', 'count': 1, 'height': 28, 'width': 28}
  55. assert os.path.exists("media/images/image_summary.jpg")
  56. def test_matplot_image(summary):
  57. img = plt.imshow(np.random.rand(28, 28), cmap='gray')
  58. summary["fig"] = img
  59. plt.close()
  60. assert disk_summary()["fig"] == {
  61. "_type": "images", "count": 1, "height": 480, "width": 640}
  62. assert os.path.exists("media/images/fig_summary.jpg")
  63. def test_matplot_plotly(summary):
  64. plt.plot([1, 2, 3])
  65. summary["plot"] = plt
  66. plt.close()
  67. plot = disk_summary()["plot"]
  68. assert plot["_type"] == "plotly"
  69. def test_plotly_plot(summary):
  70. summary["plot"] = go.Scatter(x=[0, 1, 2])
  71. plot = disk_summary()["plot"]
  72. assert plot["_type"] == "plotly"
  73. assert plot["plot"]['type'] == 'scatter'
  74. def test_newline(summary):
  75. summary["rad \n"] = 1
  76. summary.update({"bad \n ": 2})
  77. summ = disk_summary()
  78. assert summ["rad"] == 1
  79. assert summ["bad"] == 2
  80. def test_big_numpy(summary):
  81. summary.update({"rad": np.random.rand(1000)})
  82. assert disk_summary()["rad"]["max"] > 0
  83. assert os.path.exists("wandb.h5")
  84. def test_big_nested_numpy(summary):
  85. summary.update({"rad": {"deep": np.random.rand(1000)}})
  86. assert disk_summary()["rad"]["deep"]["max"] > 0
  87. assert os.path.exists("wandb.h5")
  88. def test_torch_tensor(summary):
  89. summary.update({"pytorch": torch.rand(1000, 1000)})
  90. assert os.path.exists("wandb.h5")
  91. assert disk_summary()["pytorch"]["_type"] == "torch.Tensor"
  92. def test_tensorflow_tensor(summary):
  93. with tf.Session().as_default():
  94. summary.update({"tensorflow": tf.random_normal([1000])})
  95. assert os.path.exists("wandb.h5")
  96. assert disk_summary()["tensorflow"]["_type"] == "tensorflow.Tensor"
  97. def test_pandas(summary):
  98. summary.update({"pandas": pd.DataFrame(data=np.random.rand(1000))})
  99. assert os.path.exists("wandb.h5")
  100. parsed = disk_summary()
  101. print(parsed)
  102. assert parsed["pandas"]["_type"] == "pandas.DataFrame"
  103. def test_read_numpy(summary):
  104. summary.update({"rad": np.random.rand(1000)})
  105. s = FileSummary()
  106. assert len(s["rad"]) == 1000
  107. def test_read_nested_numpy(summary):
  108. summary.update({"rad": {"deep": np.random.rand(1000)}})
  109. s = FileSummary()
  110. assert len(s["rad"]["deep"]) == 1000
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...