-
Notifications
You must be signed in to change notification settings - Fork 213
Tensorboard Issue #932 #936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ee3722a
32ad2c6
352f8b5
b086567
79a0138
c037b1a
ec228a0
c01b8e6
3ce69ec
fb51155
d30c285
63eed94
a8cef18
97fd763
c5b9eac
4bcfe2d
785d752
a89b7de
02d0f57
886bde5
59e7306
0ac598a
2bc591e
8c5f715
6aa4df8
0641d2d
52edc57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,9 +23,9 @@ SOFTWARE. | |
| This software incorporates material from third parties listed below: | ||
|
|
||
| ================== | ||
|
|
||
| From PyTorch | ||
|
|
||
| Copyright (c) 2016- Facebook, Inc (Adam Paszke) | ||
| Copyright (c) 2014- Facebook, Inc (Soumith Chintala) | ||
| Copyright (c) 2011-2014 Idiap Research Institute (Ronan Collobert) | ||
|
|
@@ -35,54 +35,54 @@ Copyright (c) 2011-2013 NYU (Clement Farabet) | |
| Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston) | ||
| Copyright (c) 2006 Idiap Research Institute (Samy Bengio) | ||
| Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz) | ||
|
|
||
| From Caffe2: | ||
|
|
||
| Copyright (c) 2016-present, Facebook Inc. All rights reserved. | ||
|
|
||
| All contributions by Facebook: | ||
| Copyright (c) 2016 Facebook Inc. | ||
|
|
||
| All contributions by Google: | ||
| Copyright (c) 2015 Google Inc. | ||
| All rights reserved. | ||
|
|
||
| All contributions by Yangqing Jia: | ||
| Copyright (c) 2015 Yangqing Jia | ||
| All rights reserved. | ||
|
|
||
| All contributions from Caffe: | ||
| Copyright(c) 2013, 2014, 2015, the respective contributors | ||
| All rights reserved. | ||
|
|
||
| All other contributions: | ||
| Copyright(c) 2015, 2016 the respective contributors | ||
| All rights reserved. | ||
|
|
||
| Caffe2 uses a copyright model similar to Caffe: each contributor holds | ||
| copyright over their contributions to Caffe2. The project versioning records | ||
| all such contribution and copyright details. If a contributor wants to further | ||
| mark their specific copyright on a particular contribution, they should | ||
| indicate their copyright solely in the commit message of the change when it is | ||
| committed. | ||
|
|
||
| All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions are met: | ||
|
|
||
| 1. Redistributions of source code must retain the above copyright | ||
| notice, this list of conditions and the following disclaimer. | ||
|
|
||
| 2. Redistributions in binary form must reproduce the above copyright | ||
| notice, this list of conditions and the following disclaimer in the | ||
| documentation and/or other materials provided with the distribution. | ||
|
|
||
| 3. Neither the names of Facebook, Deepmind Technologies, NYU, NEC Laboratories America | ||
| and IDIAP Research Institute nor the names of its contributors may be | ||
| used to endorse or promote products derived from this software without | ||
| specific prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
|
|
@@ -591,4 +591,62 @@ Apache License | |
| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
| ================== | ||
| Android Code(gif_encoder) | ||
| https://cs.android.com/android/platform/superproject/+/master:external/glide/LICENSE | ||
| https://cs.android.com/android/platform/superproject/+/master:external/glide/third_party/gif_encoder/LICENSE | ||
|
|
||
| Copyright 2014 Google, Inc. All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without modification, are | ||
| permitted provided that the following conditions are met: | ||
|
|
||
| 1. Redistributions of source code must retain the above copyright notice, this list of | ||
| conditions and the following disclaimer. | ||
|
|
||
| 2. Redistributions in binary form must reproduce the above copyright notice, this list | ||
| of conditions and the following disclaimer in the documentation and/or other materials | ||
| provided with the distribution. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY GOOGLE, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED | ||
| WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
| FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE, INC. OR | ||
| CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
| ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
| ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
| The views and conclusions contained in the software and documentation are those of the | ||
| authors and should not be interpreted as representing official policies, either expressed | ||
| or implied, of Google, Inc. | ||
| --------------------------------------------------------------------------------------------- | ||
|
|
||
| License for Encoder.cs and LZWEncoder.cs | ||
|
|
||
| No copyright asserted on the source code of this class. May be used for any | ||
| purpose, however, refer to the Unisys LZW patent for restrictions on use of | ||
| the associated LZWEncoder class. Please forward any corrections to | ||
| [email protected]. | ||
|
|
||
| ----------------------------------------------------------------------------- | ||
| License for NeuQuant.cs | ||
|
|
||
| Copyright (c) 1994 Anthony Dekker | ||
|
|
||
| NEUQUANT Neural-Net quantization algorithm by Anthony Dekker, 1994. See | ||
| "Kohonen neural networks for optimal colour quantization" in "Network: | ||
| Computation in Neural Systems" Vol. 5 (1994) pp 351-367. for a discussion of | ||
| the algorithm. | ||
|
|
||
| Any party obtaining a copy of these files from the author, directly or | ||
| indirectly, is granted, free of charge, a full and unrestricted irrevocable, | ||
| world-wide, paid up, royalty-free, nonexclusive right and license to deal in | ||
| this software and documentation files (the "Software"), including without | ||
| limitation the rights to use, copy, modify, merge, publish, distribute, | ||
| sublicense, and/or sell copies of the Software, and to permit persons who | ||
| receive copies from any such party to do so, with the only requirement being | ||
| that this copyright notice remain intact. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // Copyright (c) .NET Foundation and Contributors. All Rights Reserved. See LICENSE in the project root for license information. | ||
| using System; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Net.Http; | ||
| using System.Threading.Tasks; | ||
| using SixLabors.ImageSharp; | ||
| using SixLabors.ImageSharp.PixelFormats; | ||
| using SkiaSharp; | ||
| using static TorchSharp.torch; | ||
|
|
||
| namespace TorchSharp.Examples | ||
| { | ||
| public static class Tensorboard | ||
| { | ||
| private static string imagePath = "TensorboardExample/Images"; | ||
| internal static async Task Main(string[] args) | ||
| { | ||
| await DownloadExampleData("https://agirls.aottercdn.com/media/0d532b3f-0196-466a-96e1-7c6db56d0142.gif"); | ||
| var device = cuda.is_available() ? CUDA : CPU; | ||
| var writer = utils.tensorboard.SummaryWriter("tensorboard"); | ||
| Console.WriteLine($"Running Tensorboard on {device.type}"); | ||
| AddText(writer); | ||
| AddImageUsePath(writer); | ||
| AddImageUseTensor(writer, device); | ||
| AddVideo(writer, device); | ||
| AddHistogram(writer, device); | ||
| } | ||
|
|
||
| private static void AddHistogram(Modules.SummaryWriter writer, Device device) | ||
| { | ||
| for (int i = 0; i < 10; i++) { | ||
| Tensor x = randn(1000, device: device); | ||
| writer.add_histogram("AddHistogram", x + i, i); | ||
| } | ||
| } | ||
|
|
||
| private static void AddText(Modules.SummaryWriter writer) | ||
| { | ||
| writer.add_text("AddText", "step_1", 1); | ||
| writer.add_text("AddText", "step_2", 2); | ||
| writer.add_text("AddText", "step_3", 3); | ||
| writer.add_text("AddText", "step_4", 4); | ||
| writer.add_text("AddText", "step_5", 5); | ||
| } | ||
|
|
||
| private static void AddImageUsePath(Modules.SummaryWriter writer) | ||
| { | ||
| var imagesPath = Directory.GetFiles(imagePath); | ||
| for (var i = 0; i < imagesPath.Length; i++) { | ||
| writer.add_img("AddImageUsePath", imagesPath[i], i); | ||
| } | ||
| } | ||
ChengYen-Tang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private static void AddImageUseTensor(Modules.SummaryWriter writer, Device device) | ||
| { | ||
| var images = Directory.GetFiles(imagePath).Select(item => SKBitmap.Decode(item)).ToArray(); | ||
| using var d = NewDisposeScope(); | ||
| for (var i = 0; i < images.Length; i++) { | ||
| var tensor = SKBitmapToTensor(images[i], device); | ||
| writer.add_img("AddImageUseTensor", tensor, i, dataformats: "CHW"); | ||
| images[i].Dispose(); | ||
| } | ||
| } | ||
|
|
||
| private static void AddVideo(Modules.SummaryWriter writer, Device device) | ||
| { | ||
| var images = Directory.GetFiles(imagePath).Select(item => SKBitmap.Decode(item)).ToArray(); | ||
| using var d = NewDisposeScope(); | ||
| var tensor = stack(images.Select(item => SKBitmapToTensor(item, device)).ToArray()); | ||
| tensor = stack(new Tensor[] { tensor, tensor, tensor, tensor, tensor, tensor, tensor, tensor, tensor, tensor }); | ||
| foreach (var image in images) | ||
| image.Dispose(); | ||
| writer.add_video("AddVideo", tensor, 1, 10); | ||
| writer.add_video("AddVideo", tensor, 2, 10); | ||
| writer.add_video("AddVideo", tensor, 3, 10); | ||
| } | ||
|
|
||
| private static Tensor SKBitmapToTensor(SKBitmap skBitmap, Device device) | ||
| { | ||
| var width = skBitmap.Width; | ||
| var height = skBitmap.Height; | ||
| var hwcData = new byte[4, height, width]; | ||
| for (var y = 0; y < height; y++) { | ||
| for (var x = 0; x < width; x++) { | ||
| var color = skBitmap.GetPixel(x, y); | ||
| hwcData[0, y, x] = color.Red; | ||
| hwcData[1, y, x] = color.Green; | ||
| hwcData[2, y, x] = color.Blue; | ||
| hwcData[3, y, x] = color.Alpha; | ||
| } | ||
| } | ||
|
|
||
| return tensor(hwcData, ScalarType.Byte, device); | ||
| } | ||
|
|
||
| private static async Task DownloadExampleData(string url) | ||
| { | ||
| if (Directory.Exists(imagePath)) | ||
| Directory.Delete(imagePath, true); | ||
| Directory.CreateDirectory(imagePath); | ||
| using var client = new HttpClient(); | ||
|
|
||
| using var message = await client.GetAsync(url); | ||
| using var stream = await message.Content.ReadAsStreamAsync(); | ||
| using var animatedImage = Image.Load<Rgba32>(stream); | ||
| for (var i = 0; i < animatedImage.Frames.Count; i++) { | ||
| var pngFilename = Path.Combine(imagePath, $"frame_{i}.png"); | ||
| using var pngImage = animatedImage.Frames.CloneFrame(i); | ||
| pngImage.SaveAsPng(pngFilename); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -628,17 +628,6 @@ public static Tensor[] meshgrid(IEnumerable<Tensor> tensors, string indexing = " | |
| /// </summary> | ||
| public static Tensor roll(Tensor input, ReadOnlySpan<long> shifts, ReadOnlySpan<long> dims = default) => input.roll(shifts, dims); | ||
|
|
||
| // https://pytorch.org/docs/stable/generated/torch.searchsorted | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| [Obsolete("not implemented", true)] | ||
| static Tensor searchsorted( | ||
| Tensor sorted_sequence, | ||
| Tensor values, | ||
| bool out_int32 = false, | ||
| bool right = false, | ||
| side side = side.left, | ||
| Tensor? sorter = null) | ||
| => throw new NotImplementedException(); | ||
|
|
||
| // https://pytorch.org/docs/stable/generated/torch.tensordot | ||
| /// <summary> | ||
| /// Returns a contraction of <paramref name="a"/> and <paramref name="b"/> over multiple dimensions. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| namespace TorchSharp.Utils.tensorboard.Enums | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this enum declared in two places?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This enum has one more tensorflow item. |
||
| { | ||
| public enum HistogramBinSelector : byte | ||
| { | ||
| Doane = 0, | ||
| Rice, | ||
| Scott, | ||
| Sqrt, | ||
| Stone, | ||
| Sturges, | ||
| Tensorflow | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.