-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into Charlemagne-low-level-api
- Loading branch information
Showing
28 changed files
with
1,351 additions
and
252 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
#!/usr/bin/env python | ||
|
||
# Test logging media alone, in dicts, lists, and data frames. | ||
# Add to both history and summary. | ||
|
||
import os | ||
import subprocess | ||
|
||
import numpy | ||
import pandas | ||
import PIL | ||
from pkg_resources import parse_version | ||
import plotly.graph_objs as go | ||
import matplotlib.pyplot as plt | ||
import tensorflow | ||
import torch | ||
from torchvision import models | ||
import wandb | ||
|
||
|
||
def dummy_torch_tensor(size, requires_grad=True): | ||
if parse_version(torch.__version__) >= parse_version('0.4'): | ||
return torch.ones(size, requires_grad=requires_grad) | ||
else: | ||
return torch.autograd.Variable(torch.ones(size), requires_grad=requires_grad) | ||
|
||
|
||
def main(): | ||
wandb.init() | ||
|
||
histogram_small_literal = wandb.Histogram(np_histogram=([1, 2, 4], [3, 10, 20, 0])) | ||
histogram_large_random = wandb.Histogram(numpy.random.randint(255, size=(1000))) | ||
numpy_array = numpy.random.rand(1000) | ||
torch_tensor = torch.rand(1000, 1000) | ||
data_frame = pandas.DataFrame(data=numpy.random.rand(1000), columns=['col']) | ||
tensorflow_variable_single = tensorflow.Variable(543.01, tensorflow.float32) | ||
tensorflow_variable_multi = tensorflow.Variable([[2, 3], [7, 11]], tensorflow.int32) | ||
plot_scatter = go.Figure( # plotly | ||
data=go.Scatter(x=[0, 1, 2]), | ||
layout=go.Layout( | ||
title=go.layout.Title(text="A Bar Chart"))) | ||
|
||
image_data = numpy.zeros((28, 28)) | ||
image_cool = wandb.Image(image_data, caption="Cool zeros") | ||
image_nice = wandb.Image(image_data, caption="Nice zeros") | ||
image_random = wandb.Image(numpy.random.randint(255, size=(28, 28, 3))) | ||
image_pil = wandb.Image(PIL.Image.new("L", (28, 28))) | ||
plt.plot([1, 2, 3, 4]) | ||
plt.ylabel('some interesting numbers') | ||
image_matplotlib_plot = wandb.Image(plt) | ||
matplotlib_plot = plt | ||
|
||
audio_data = numpy.random.uniform(-1, 1, 44100) | ||
sample_rate = 44100 | ||
caption1 = "This is what a dog sounds like" | ||
caption2 = "This is what a chicken sounds like" | ||
# test with all captions | ||
audio1 = wandb.Audio(audio_data, sample_rate=sample_rate, caption=caption1) | ||
audio2 = wandb.Audio(audio_data, sample_rate=sample_rate, caption=caption2) | ||
# test with no captions | ||
audio3 = wandb.Audio(audio_data, sample_rate=sample_rate) | ||
audio4 = wandb.Audio(audio_data, sample_rate=sample_rate) | ||
# test with some captions | ||
audio5 = wandb.Audio(audio_data, sample_rate=sample_rate) | ||
audio6 = wandb.Audio(audio_data, sample_rate=sample_rate, caption=caption2) | ||
|
||
html = wandb.Html("<html><body><h1>Hello</h1></body></html>") | ||
|
||
table_default_columns = wandb.Table() | ||
table_default_columns.add_data("Some awesome text", "Positive", "Negative") | ||
|
||
table_custom_columns = wandb.Table(["Foo", "Bar"]) | ||
table_custom_columns.add_data("So", "Cool") | ||
table_custom_columns.add_data("&", "Rad") | ||
|
||
#plot_figure = matplotlib.pyplot.plt.figure() | ||
#c1 = matplotlib.pyplot.plt.Circle((0.2, 0.5), 0.2, color='r') | ||
#ax = matplotlib.pyplot.plt.gca() | ||
#ax.add_patch(c1) | ||
#matplotlib.pyplot.plt.axis('scaled') | ||
|
||
# pytorch model graph | ||
alex = models.AlexNet() | ||
graph = wandb.wandb_torch.TorchGraph.hook_torch(alex) | ||
alex.forward(dummy_torch_tensor((2, 3, 224, 224))) | ||
|
||
|
||
with tensorflow.Session().as_default() as sess: | ||
sess.run(tensorflow.global_variables_initializer()) | ||
|
||
wandb.run.summary.update({ | ||
'histogram-small-literal-summary': histogram_small_literal, | ||
'histogram-large-random-summary': histogram_large_random, | ||
'numpy-array-summary': numpy_array, | ||
'torch-tensor-summary': torch_tensor, | ||
'data-frame-summary': data_frame, | ||
|
||
'image-cool-summary': image_cool, | ||
'image-nice-summary': image_nice, | ||
'image-random-summary': image_random, | ||
'image-pil-summary': image_pil, | ||
'image-plot-summary': image_matplotlib_plot, | ||
'image-list-summary': [image_cool, image_nice, image_random, image_pil], | ||
|
||
# Doesn't work, because something has happened to the MPL object (MPL may | ||
# be doing magical scope stuff). If you log it right after creating it, | ||
# it works fine. | ||
# 'matplotlib-plot': matplotlib_plot, | ||
|
||
'audio1-summary': audio1, | ||
'audio2-summary': audio2, | ||
'audio3-summary': audio3, | ||
'audio4-summary': audio4, | ||
'audio5-summary': audio5, | ||
'audio6-summary': audio6, | ||
'audio-list-summary': [audio1, audio2, audio3, audio4, audio5, audio6], | ||
|
||
'html-summary': html, | ||
|
||
'table-default-columns-summary': table_default_columns, | ||
'table-custom-columns-summary': table_custom_columns, | ||
|
||
'plot-scatter-summary': plot_scatter, | ||
#'plot_figure': plot_figure, | ||
|
||
'tensorflow-variable-single-summary': tensorflow_variable_single, | ||
'tensorflow-variable-multi-summary': tensorflow_variable_multi, | ||
|
||
'graph-summary': graph, | ||
}) | ||
|
||
for i in range(10): | ||
wandb.run.history.add({ | ||
'string': 'string', | ||
'histogram-small-literal': histogram_small_literal, | ||
'histogram-large-random': histogram_large_random, | ||
'numpy-array': numpy_array, | ||
'torch-tensor': torch_tensor, | ||
#'data-frame': data_frame, # not supported yet | ||
|
||
'image-cool': image_cool, | ||
'image-nice': image_nice, | ||
'image-random': image_random, | ||
'image-pil': image_pil, | ||
'image-plot': image_matplotlib_plot, | ||
'image-list': [image_cool, image_nice, image_random, image_pil], | ||
|
||
# 'matplotlib-plot': matplotlib_plot, | ||
|
||
'audio1': audio1, | ||
'audio2': audio2, | ||
'audio3': audio3, | ||
'audio4': audio4, | ||
'audio5': audio5, | ||
'audio6': audio6, | ||
'audio-list': [audio1, audio2, audio3, audio4, audio5, audio6], | ||
|
||
'html': html, | ||
|
||
'table-default-columns': table_default_columns, | ||
'table-custom-columns': table_custom_columns, | ||
|
||
'plot-scatter': plot_scatter, | ||
#'plot_figure': plot_figure, | ||
|
||
'tensorflow-variable-single': tensorflow_variable_single, | ||
'tensorflow-variable-multi': tensorflow_variable_multi, | ||
|
||
#'graph': graph, | ||
}) | ||
|
||
wandb.run.summary.update({ | ||
'histogram-small-literal-summary': histogram_small_literal, | ||
'histogram-large-random-summary': histogram_large_random, | ||
'numpy-array-summary': numpy_array, | ||
'torch-tensor-summary': torch_tensor, | ||
'data-frame-summary': data_frame, | ||
|
||
'image-cool-summary': image_cool, | ||
'image-nice-summary': image_nice, | ||
'image-random-summary': image_random, | ||
'image-pil-summary': image_pil, | ||
'image-plot-summary': image_matplotlib_plot, | ||
'image-list-summary': [image_cool, image_nice, image_random, image_pil], | ||
|
||
# 'matplotlib-plot': matplotlib_plot, | ||
|
||
'audio1-summary': audio1, | ||
'audio2-summary': audio2, | ||
'audio3-summary': audio3, | ||
'audio4-summary': audio4, | ||
'audio5-summary': audio5, | ||
'audio6-summary': audio6, | ||
'audio-list-summary': [audio1, audio2, audio3, audio4, audio5, audio6], | ||
|
||
'html-summary': html, | ||
|
||
'table-default-columns-summary': table_default_columns, | ||
'table-custom-columns-summary': table_custom_columns, | ||
|
||
'plot-scatter-summary': plot_scatter, | ||
#'plot_figure': plot_figure, | ||
|
||
'tensorflow-variable-single-summary': tensorflow_variable_single, | ||
'tensorflow-variable-multi-summary': tensorflow_variable_multi, | ||
|
||
'graph-summary': graph, | ||
}) | ||
|
||
#history.add({ | ||
# "tensorflow_variable_single": tensorflow_variable_single, | ||
# "tensorflow_variable_multi": tensorflow_variable_single, | ||
#}) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import wandb | ||
import numpy as np | ||
import time | ||
import tensorflow as tf | ||
import glob | ||
import os | ||
|
||
#wandb.init(project="tf2", sync_tensorboard=True, resume=True) | ||
wandb.init(sync_tensorboard=True, resume=True) | ||
|
||
wandb.config['nice'] = 'So cool fun' | ||
|
||
|
||
class Logger(tf.keras.callbacks.Callback): | ||
def on_epoch_end(self, epoch, logs): | ||
time.sleep(2) | ||
wandb.log({"wild_metrics": logs, "interval": epoch * 10}) | ||
|
||
|
||
model = tf.keras.models.Sequential() | ||
model.add(tf.keras.layers.Conv2D( | ||
3, 3, activation="relu", input_shape=(28, 28, 1))) | ||
model.add(tf.keras.layers.Flatten()) | ||
model.add(tf.keras.layers.Dense(10, activation="softmax")) | ||
model.compile(loss="sparse_categorical_crossentropy", | ||
optimizer="sgd", metrics=["accuracy"]) | ||
|
||
model.fit(np.ones((10, 28, 28, 1)), np.ones((10,)), epochs=17, | ||
validation_split=0.2, callbacks=[Logger(), tf.keras.callbacks.TensorBoard()]) |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import wandb | ||
import keras | ||
import numpy as np | ||
import tensorflow as tf | ||
from wandb.keras import WandbCallback | ||
|
||
#wandb.init(project="tf2") | ||
wandb.init() | ||
|
||
model = tf.keras.models.Sequential() | ||
model.add(tf.keras.layers.Conv2D( | ||
3, 3, activation="relu", input_shape=(28, 28, 1))) | ||
model.add(tf.keras.layers.Flatten()) | ||
model.add(tf.keras.layers.Dense(10, activation="softmax")) | ||
model.compile(loss="sparse_categorical_crossentropy", | ||
optimizer="sgd", metrics=["accuracy"]) | ||
|
||
model.fit(np.ones((10, 28, 28, 1)), np.ones((10,)), epochs=7, | ||
validation_split=0.2, callbacks=[WandbCallback()]) |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env python | ||
|
||
# Numpy Clouds | ||
# http://app.wandb.ai/nbaryd/client-standalone_tests/runs/ly8g46vm?workspace=user-nbaryd | ||
|
||
# 3D models | ||
# http://app.test/nbaryd/client-standalone_tests/runs/0rb3xwke?workspace=user-nbaryd | ||
|
||
import os | ||
|
||
import numpy as np | ||
import wandb | ||
from math import sin, cos, pi | ||
|
||
|
||
DIR = os.path.dirname(__file__) | ||
|
||
|
||
point_cloud_1 = np.array([[0, 0, 0, 1], | ||
[0, 0, 1, 13], | ||
[0, 1, 0, 2], | ||
[0, 1, 0, 4]]) | ||
|
||
point_cloud_2 = np.array([[0, 0, 0], | ||
[0, 0, 1], | ||
[0, 1, 0], | ||
[0, 1, 0]]) | ||
|
||
# Generate a symetric pattern | ||
POINT_COUNT = 20000 | ||
|
||
# Choose a random sample | ||
theta_chi = pi * np.random.rand(POINT_COUNT, 2) | ||
|
||
|
||
def gen_point(theta, chi, i): | ||
p = sin(theta) * 4.5 * sin(i + 1 / 2 * (i * i + 2)) + \ | ||
cos(chi) * 7 * sin((2 * i - 4) / 2 * (i + 2)) | ||
|
||
x = p * sin(chi) * cos(theta) | ||
y = p * sin(chi) * sin(theta) | ||
z = p * cos(chi) | ||
|
||
r = sin(theta) * 120 + 120 | ||
g = sin(x) * 120 + 120 | ||
b = cos(y) * 120 + 120 | ||
|
||
return [x, y, z, r, g, b] | ||
|
||
|
||
def wave_pattern(i): | ||
return np.array([gen_point(theta, chi, i) for [theta, chi] in theta_chi]) | ||
|
||
|
||
wandb.init() | ||
|
||
# Tests 3d OBJ | ||
|
||
#wandb.log({"gltf": wandb.Object3D(open(os.path.join(DIR, "../tests/fixtures/Duck.gltf"))), | ||
# "obj": wandb.Object3D(open(os.path.join(DIR, "../tests/fixtures/cube.obj")))}) | ||
|
||
# Tests numpy clouds | ||
for i in range(0, 20, 10): | ||
wandb.log({"Clouds": [wandb.Object3D(point_cloud_1), wandb.Object3D(point_cloud_2)], | ||
"Colored_Cloud": wandb.Object3D(wave_pattern(i))}) |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import wandb | ||
import torch | ||
import torch.nn as nn | ||
import torch.nn.functional as F | ||
from torch.utils.tensorboard import SummaryWriter | ||
|
||
wandb.init(tensorboard=True) | ||
|
||
|
||
class ConvNet(nn.Module): | ||
def __init__(self): | ||
super(ConvNet, self).__init__() | ||
self.conv1 = nn.Conv2d(1, 10, kernel_size=5) | ||
self.conv2 = nn.Conv2d(10, 20, kernel_size=5) | ||
self.conv2_drop = nn.Dropout2d() | ||
self.fc1 = nn.Linear(320, 50) | ||
self.fc2 = nn.Linear(50, 10) | ||
|
||
def forward(self, x): | ||
x = F.relu(F.max_pool2d(self.conv1(x), 2)) | ||
x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2)) | ||
x = x.view(-1, 320) | ||
x = F.relu(self.fc1(x)) | ||
x = F.dropout(x, training=self.training) | ||
x = self.fc2(x) | ||
return F.log_softmax(x, dim=1) | ||
|
||
|
||
writer = SummaryWriter() | ||
net = ConvNet() | ||
wandb.watch(net, log_freq=2) | ||
for i in range(10): | ||
output = net(torch.ones((64, 1, 28, 28))) | ||
loss = F.mse_loss(output, torch.ones((64, 10))) | ||
output.backward(torch.ones(64, 10)) | ||
writer.add_scalar("loss", loss / 64, i+1) | ||
writer.add_image("example", torch.ones((1, 28, 28)), i+1) | ||
writer.close() |
Oops, something went wrong.