Skip to main content

Tool for generating App Inventor extension skeletons from Tensorflow.js models

Project description

MIT App Inventor TFJS Extension Generator

The aim of this tool is to make it easier to generate the scaffolding needed to use a Tensorflow.js model in App Inventor.

Quickstart

Install dependencies:

  • java 8
  • ant 1.10
  • python 3
  • node
  • npm
  • git

Install the App Inventor TFJS extension generator using pip:

pip install appinventor-tfjs

Create an extension prototype for Posenet:

python -m appinventor.tfjs posenet edu.mit.appinventor.ai.posenet.PosenetExtension

The output of this command will be a new directory called PosenetExtension. Within this directory, you will find a fresh git clone of the App Inventor extension template repository. The directory will have the following structure:

build.xml
lib
 ├─ android
 │   ├─ android.jar
 │   ├─ appcompat-v7-28.0.0.jar
 │   └─ dx.jar
 ├─ ant-contrib
 │   └─ ant-contrib-1.0b3.jar
 ├─ appinventor
 │   └─ AndroidRuntime.jar
 │   └─ AnnotationProcessors.jar
 └─ deps
README.md
src
 └─ edu
     └─ mit
         └─ appinventor
             └─ ai
                 └─ posenet
                     ├─ assets
                     │   ├─ app.js
                     │   ├─ group1-shard1of2.bin
                     │   ├─ group1-shard2of2.bin
                     │   ├─ index.html
                     │   ├─ model-stride16.json
                     │   ├─ posenet.min.js
                     │   ├─ tf-converter.min.js
                     │   ├─ tf-core.min.js
                     │   └─ VERSIONS
                     └─ PosenetExtension.java

Of those files, the ones under src are most interesting. Briefly:

  • PosenetExtension.java - Boilerplate extension code for a TFJS extneion in App Inventor. You will want to customize it to provide model-specific behavior, such as interpreting the results before passing information back to the blocks layer.
  • app.js - Boilerplate Javascript code to load the model and interact with the Java code in the App Inventor extension. You will need to modify this to interact correctly with the TFJS model, such as calling the correct method to start the model and interpret its output for App Inventor.
  • group-*.bin - These are the weights at each level of the model, pulled from the TFJS model repository. The number of files will vary based on the size of the model.
  • index.html - The index.html file loads all of the prerequisite Javascript files. It generally does not need to be modified.
  • *.min.js - Minified Javascript code for the model and any dependencies, such as tfjs-core and tfjs-converter.
  • VERSIONS - The VERSIONS file contains a key-value mapping the different npm modules to the versions that were retrieved. There should be one entry per min.js file.

Usage

usage: python -m appinventor.tfjs [-h] [--scope SCOPE] model_name class_name

Create a TensorFlow.js-based extension for MIT App Inventor.

positional arguments:
  model_name
  class_name

optional arguments:
  -h, --help     show this help message and exit
  --scope SCOPE

The model_name argument names the Tensorflow.js model of interest. A list of pretrained models is available on GitHub. For example, if you are interested in trying the MobileNet model, you would specify mobilenet as the model_name.

The class_name argument specifies a fully qualified Java class name that will be used for the extension. For example, a MobileNet extension for App Inventor might have the fully qualified class name com.example.tfjs.mobile.MobileNetExtension. The extension generator will create this class and any intermediate packages for you.

The optional --scope SCOPE argument allows you to import models from npm packages that are not under the @tensorflow-models namespace (effectively, if --scope is not specified it is the same as --scope @tensorflow-models).

Development

Dependencies

You will need to create a virtual environment and install the dependencies by running. We provide instructions for macOS below.

Create a virtualenv

macOS

  1. Install Homebrew

  2. Install pyenv

    brew install pyenv
    echo "eval \"\$(pyenv init -)\"" >> ~/.bash_profile
    echo "eval \"\$(pyenv virtualenv-init -)\"" >> ~/.bash_profile
    source ~/.bash_profile
    
  3. Create a python environment using pyenv and activate it

    pyenv install 3.6
    pyenv virtualenv 3.6 appinventor3
    pyenv activate appinventor3
    

Install dependencies

pip install -r requirements.txt
pip install .

Contributing

This software is made available under the Apache Software License 2.0. You are welcome to contribute pull requests to this project via GitHub.

License

Copyright 2020 Massachusetts Institute of Technology

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

appinventor-tfjs-0.1.4.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

appinventor_tfjs-0.1.4-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file appinventor-tfjs-0.1.4.tar.gz.

File metadata

  • Download URL: appinventor-tfjs-0.1.4.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for appinventor-tfjs-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c0ceb1e898a0c4d134b970f125c988fb65021b104b98fe12a362f5240425126a
MD5 8ac95a6bddaec2ccb7e04a56110ee5b4
BLAKE2b-256 2d77110aa33089b8cd0edc529500e10ecf217a869e919a0a52bcf38c0e62b111

See more details on using hashes here.

File details

Details for the file appinventor_tfjs-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: appinventor_tfjs-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for appinventor_tfjs-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 581fbabfb836c377e4ef553da52b975a0ba790033f77699e053dc3cb80f7e3dc
MD5 04c51689fb8265cdede14e01d6534145
BLAKE2b-256 51e9463446c500e57398c61f686bf2488c4b949d3ac2f8d658b3c5d719f9d16c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page