GithubHelp home page GithubHelp logo

vojtamolda / tensor-thumbnail Goto Github PK

View Code? Open in Web Editor NEW
13.0 13.0 1.0 2.15 MB

Library for displaying small previews of Tensors. Useful for working with TensorFlow in Swift.

License: Apache License 2.0

Swift 100.00%
swift tensorflow thumbnail

tensor-thumbnail's People

Contributors

vojtamolda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

philipturner

tensor-thumbnail's Issues

Visualization beyond the 3rd dimension

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.

Quick Look in Xcode Debugger doesn't work

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:

Quick Look in Xcode Debugger

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.