vojtamolda / tensor-thumbnail Goto Github PK
View Code? Open in Web Editor NEWLibrary for displaying small previews of Tensors. Useful for working with TensorFlow in Swift.
License: Apache License 2.0
Library for displaying small previews of Tensors. Useful for working with TensorFlow in Swift.
License: Apache License 2.0
Generally, visualizing higher-dimensional spaces is a tricky problem that has a tendency to quite a bit mess with one's brain ๐ป. So most likely there's not going to be a silver bullet solution that pleases everybody.
The key objective of the visualization diagram is clarity. It should be possible to look at the diagram and intuitively reconstruct back the exact shape of the tensor. The diagram should also try to display the dimensions in proportion to each other. So it is clear at the first sight how two tensors can be multiplied or how to feed them to a neural network layer.
Typical use-case of higher dimensional diagram is an input tensor of a 2D convolution layer. Most frequently used convention for a batch of images is [B, C, H, W]
. Meaning of the dimensions is the following: B
- batch size, C
- number of channels, H
- height and W
- width.
Clicking the ๐๏ธ icon in Xcode Debugger displays very useful previews for built-in types. For example it can show a preview of an image, color, cursor, bezier path and many more types.
Here's an example:
Since about 2014 it is possible to implement custom quick look behavior for user defined data types. Here is Apple's official documentation on how to do it.
Unfortunately, as of Xcode 12 custom quick look isn't possible for structs. To the extent of my knowledge the debugQuickLookObject()
method is called only for classes. It requires @objc
decorator responsible for Objective-C bridging in order to work properly. Since TensorFlow.Tensor
is a struct there's no way to implement this feature unless Apple decides to allow it and changes the implementation in Xcode.
Below is an example main.swift
file that demonstrates the problem. When debugging the application QuickLookClass
shows a nice rectangle view after clicking the quick look icon. Whereas QuickLookStruct
doesn't show anything even tough the implementation is identical
import SwiftUI
/// A simple example view.
struct RedRectangleView: View {
var body: some View {
Rectangle()
.fill()
.foregroundColor(.red)
.cornerRadius(5)
}
}
/// A class with working Quick Look in Xcode Debugger.
class QuickLookClass {
init() { }
@objc
func debugQuickLookObject() -> NSView {
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 20, height: 20),
styleMask: [.borderless], backing: .buffered, defer: false)
window.contentView = NSHostingView(rootView: RedRectangleView())
return window.contentView!
}
}
/// A struct with broken Quick Look in Xcode Debugger.
struct QuickLookStruct {
init() { }
func debugQuickLookObject() -> NSView {
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 20, height: 20),
styleMask: [.borderless], backing: .buffered, defer: false)
window.contentView = NSHostingView(rootView: RedRectangleView())
return window.contentView!
}
}
let qlClass = QuickLookClass()
let qlStruct = QuickLookStruct()
print(qlStruct, qlClass)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.