npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@magenta/image

v0.2.1

Published

Visual art with machine learning, in the browser.

Downloads

18

Readme

@magenta/image

This JavaScript implementation of Magenta's image models uses TensorFlow.js for GPU-accelerated inference.

Complete documentation is available at https://tensorflow.github.io/magenta-js/image.

Contents

Example Applications

You can try our hosted demos for each model and have a look at the demo code.

Supported Models

Fast Arbitrary Image Stylization

Implements Ghiasi et al.'s fast arbitrary style transfer model (paper, code). Wraps around Reiichiro Nakano's TensorFlow.js port of the model checkpoint.

Getting started

There are two main ways to get MagentaImage.js in your JavaScript project: via script tags or by installing it from NPM and using a build tool like yarn.

via Script Tag

Add the following code to an HTML file, and place a content (content.jpg) and style (style.jpg) image in the same directory:

<html>
  <head>
    <!-- Load @magenta/image -->
    <script src="https://cdn.jsdelivr.net/npm/@magenta/image@^0.1.2"></script>
  </head>
  <body>
    <img id="content" height="256" src="content.jpg"/>
    <img id="style" height="256" src="style.jpg"/>
    <canvas id="stylized" height="256"></canvas>
      <script>
        const model = new mi.ArbitraryStyleTransferNetwork();
        const contentImg = document.getElementById('content');
        const styleImg = document.getElementById('style');
        const stylizedCanvas = document.getElementById('stylized');

        function stylize() {
          model.stylize(contentImg, styleImg).then((imageData) => {
            stylizedCanvas.getContext('2d').putImageData(imageData, 0, 0);
          });
        }

        model.initialize().then(stylize);
      </script>
  </body>
</html>

Launch a simple HTTP server (e.g. python3 -m http.server) and point your browser to http://0.0.0.0:8000/. You should see your content and style images displayed and, after a few seconds, the stylized output.

via NPM

Add MagentaImage.js to your project using yarn or npm. For example, with yarn you can simply call yarn add @magenta/image.

Then, you can use the library in your own code as in the following example:

import * as mi from '@magenta/image';

const model = new mi.ArbitraryStyleTransferNetwork();
const contentImg = document.getElementById('content') as HTMLImageElement;
const styleImg = document.getElementById('style') as HTMLImageElement;
const stylizedCanvas = document.getElementById('stylized') as HTMLCanvasElement;

function stylize() {
  model.stylize(contentImg, styleImg).then((imageData) => {
    stylizedCanvas.getContext('2d').putImageData(imageData, 0, 0);
  });
}

model.initialize().then(stylize);

See style-transfer.glitch.me and our demos for example usage.

Example Commands

yarn install to install dependencies.

yarn test to run tests.

yarn bundle to produce a bundled version in dist/.

yarn run-demos to build and run the demo.