Why Docker?
I've spent significant amount of time to make TensorFlow Magenta to run on my Raspberry Pi 3 B+.
So I've tried and failed with the following:
TensorFlow Lite (tflite)
I was able build (it took many hours) and install tflite it on my rpi 3b+, but I was not able to find its Python bindings or clear instructions how to build them.
TensorFlow.js (tfjs)
I was able install tfjs as well. But it requires a browser like Chromium in a headless mode to use it. I decided against it as a combination of hassio and chromium is too heavy for my rpi 3b+.
TensorFlow Magenta
I've successfully installed TensorFlow. But I was not able to build Magenta. I was not able to resolve its dependency on llvmlite for the required version of llvm (7+). If someone wants to fix it, the issue is still open on Magenta GitHub.
TensorFlow Magenta on Docker
At this point I was very close to drop magenta and try something else. As well after all installations my available space on 16GB SD card was running very low.
But than I've successfully installed hassio on Docker and soon after came across TensorFlow Magenta Docker image. Even this option was recently dropped from Magenta GitHub installation instruction, but GitHub still keeps old version of the Magenta installation on Docker.
Installing Docker on Ubuntu
What I've realized soon is that this Magenta image only available for x86-64 architecture. So it can not run on my rpi 3b+. Fortunately I have some cloud based compute resources available. So )'ve provisioned a Linux VM. Then I followed instructions for initial basic security for Ubuntu setup and than Docker setup.
Getting TensorFlow Magenta Image
Installation of TensorFlow and Magenta with Docker is very simple
docker pull tensorflow/magenta
Exploring Magenta
Than I was able to get inside Magenta machine:
docker run -it -p 6006:6006 -v /tmp/magenta:/magenta-data tensorflow/magenta
The image came with some /magenta/README.md and pre-build models in /magenta/magenta/models/ :
* [**Drums RNN**](/magenta/models/drums_rnn): Applies language modeling to drum track generation using an LSTM.
* [**Image Stylization**](/magenta/models/image_stylization): A "Multistyle Pastiche Generator" that generates artistics representations of photographs. Described in [*A Learned Representation For Artistic Style*](https://arxiv.org/abs/1610.07629).
* [**Improv RNN**](/magenta/models/improv_rnn): Generates melodies a la [Melody RNN](/magenta/models/melody_rnn), but conditions the melodies on an underlying chord progression.
* [**Melody RNN**](/magenta/models/melody_rnn): Applies language modeling to melody generation using an LSTM.
* [**Music VAE**](/magenta/models/music_vae): A hierarchical recurrent variational autoencoder for music.
* [**NSynth**](/magenta/models/nsynth): "Neural Audio Synthesis" as described in [*NSynth: Neural Audio Synthesis with WaveNet Autoencoders*](https://arxiv.org/abs/1704.01279).
* [**Onsets and Frames**](/magenta/models/onsets_frames_transcription): Automatic piano music transcription model as described in [*Onsets and Frames: Dual-Objective Piano Transcription* (https://arxiv.org/abs/1710.11153)
* [**Performance RNN**](/magenta/models/performance_rnn): Applies language modeling to polyphonic music using a combination of note on/off, timeshift, and velocity change events.
* [**Pianoroll RNN-NADE**](/magenta/models/pianoroll_rnn_nade): Applies language modeling to polyphonic music generation using an LSTM combined with a NADE, an architecture called an RNN-NADE. Based on the architecture described in [*Modeling Temporal Dependencies in High-Dimensional Sequences: Application to Polyphonic Music Generation and Transcription*](http://www-etud.iro.umontreal.ca/~boulanni/ICML2012.pdf).
* [**Polyphony RNN**](/magenta/models/polyphony_rnn): Applies language modeling to polyphonic music generation using an LSTM. Based on the [BachBot](http://bachbot.com/) architecture.
* [**RL Tuner**](/magenta/models/rl_tuner): Takes an LSTM that has been trained to predict the next note in a monophonic melody and enhances it using reinforcement learning (RL). Described in [*Tuning Recurrent Neural Networks with Reinforcement Learning*](https://magenta.tensorflow.org/2016/11/09/tuning-recurrent-networks-with-reinforcement-learning/) and [*Sequence Tutor: Conservative Fine-Tuning of Sequence Generation Models with KL-control*](https://arxiv.org/abs/1611.02796)
* [**Sketch RNN**](/magenta/models/sketch_rnn): A recurrent neural network model for generating sketches. Described in [*Teaching Machines to Draw*](https://research.googleblog.com/2017/04/teaching-machines-to-draw.html) and [*A Neural Representation of Sketch Drawings*](https://arxiv.org/abs/1704.03477).
First Run
I've followed the instruction and created an output folder for generated music:
root@42115fd0c838:/magenta# mkdir /magenta-data/lookback_rnn/ root@42115fd0c838:/magenta# mkdir /magenta-data/lookback_rnn/generated
Than I've run command to generate music:
root@42115fd0c838:/magenta# melody_rnn_generate \ --config=lookback_rnn \ --bundle_file=/magenta-models/lookback_rnn.mag \ --output_dir=/magenta-data/lookback_rnn/generated \ --num_outputs=10 \ --num_steps=128 \ --primer_melody="[60]"
But it resulted in an error:
Illegal instruction (core dumped)
And the same result for other models/parameters:
root@42115fd0c838:/magenta# melody_rnn_generate --config=lookback_rnn --bundle_file=/magenta-models/lookback_rnn.mag --output_dir=/magenta-data/lookback_rnn/generated --num_outputs=10 --num_steps=128 --primer_melody="[60]" Illegal instruction (core dumped) root@42115fd0c838:/magenta# melody_rnn_generate --config=basic_rnn --bundle_file=/magenta-models/basic_rnn.mag --output_dir=/magenta-data/lookback_rnn/generated --num_outputs=10 --num_steps=128 --primer_melody="[60]" Illegal instruction (core dumped) root@42115fd0c838:/magenta# melody_rnn_generate --config=attention_rnn --bundle_file=/magenta-models/attention_rnn.mag --output_dir=/magenta-data/lookback_rnn/generated --num_outputs=10 --num_steps=128 --primer_melody="[60]" Illegal instruction (core dumped) root@42115fd0c838:/magenta# melody_rnn_generate --config=attention_rnn --bundle_file=/magenta-models/attention_rnn.mag --output_dir=/magenta-data/lookback_rnn/generated --num_outputs=1 --num_steps=128 --primer_melody="[60]" Illegal instruction (core dumped) root@42115fd0c838:/magenta# melody_rnn_generate --config=rl_rnn --bundle_file=/magenta-models/rl_rnn.mag --output_dir=/magenta-data/lookback_rnn/generated --num_outputs=1 --num_steps=128 --primer_melody="[60]" Illegal instruction (core dumped) root@42115fd0c838:/magenta# drums_rnn_generate --config=drum_kit_rnn --bundle_file=/magenta-models/drum_kit_rnn.mag --output_dir=/magenta-data/lookback_rnn/generated --num_outputs=1 --num_steps=128 --primer_melody="[60]" Illegal instruction (core dumped)
Some information about system:
root@42115fd0c838:/magenta# python --version Python 2.7.12 root@42115fd0c838:/magenta# pip list | grep tensorflow tensorflow 1.10.0 You are using pip version 18.0, however version 19.1.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. root@42115fd0c838:/magenta# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.5 LTS Release: 16.04 Codename: xenial root@42115fd0c838:/magenta# uname -i x86_64 root@42115fd0c838:/magenta# dmesg dmesg: read kernel buffer failed: Operation not permitted root@42115fd0c838:/magenta# ls -la /usr/local/lib/python2.7/dist-packages/tensorflow/libtensorflow_framework.so -rwxr-xr-x 1 root staff 16704032 Aug 8 2018 /usr/local/lib/python2.7/dist-packages/tensorflow/libtensorflow_framework.so root@42115fd0c838:/magenta# objdump -f /usr/local/lib/python2.7/dist-packages/tensorflow/libtensorflow_framework.so |grep architecture architecture: i386:x86-64, flags 0x00000150:
So now I need to investigate what wen wrong. May be TensorFlow expects GPU and my VM has only CPU. Someone already had a similar issue and I've added my error to a similar issue as well.