summaryrefslogtreecommitdiff
path: root/app/relay
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-05-25 19:54:38 +0200
committerJules Laplace <julescarbon@gmail.com>2018-05-25 19:54:38 +0200
commit5a4de48a6d63cb383832f6ef85b21699a511b755 (patch)
tree4c4fd18d26f8b5c95a6788d138ed62869357c975 /app/relay
parent1a99af129427275c22e8276e75fa4b8da6602129 (diff)
stubbing in a lot of stuff!
Diffstat (limited to 'app/relay')
-rw-r--r--app/relay/index.js6
-rw-r--r--app/relay/interpreters.js22
-rw-r--r--app/relay/modules/index.js13
-rw-r--r--app/relay/modules/pix2pix.js71
-rw-r--r--app/relay/modules/pix2pixhd.js5
-rw-r--r--app/relay/modules/samplernn.js61
-rw-r--r--app/relay/modules/test.js36
-rw-r--r--app/relay/runner.js68
8 files changed, 280 insertions, 2 deletions
diff --git a/app/relay/index.js b/app/relay/index.js
index 00f3dfa..d43f221 100644
--- a/app/relay/index.js
+++ b/app/relay/index.js
@@ -2,9 +2,11 @@ require('dotenv').config()
const io = require('socket.io-client')
const zerorpc = require('zerorpc')
-const Readable = require('stream').Readable;
+const Readable = require('stream').Readable
+const runner = require('./runner')
+
+let remote = io.connect(process.env.SOCKETIO_REMOTE)
-let remote = io.connect(process.env.SOCKETIO_REMOTE);
remote.on('cmd', (data) => {
console.log('cmd data', data)
if (! data.cmd) {
diff --git a/app/relay/interpreters.js b/app/relay/interpreters.js
new file mode 100644
index 0000000..1adb95e
--- /dev/null
+++ b/app/relay/interpreters.js
@@ -0,0 +1,22 @@
+export default {
+ pytorch: {
+ cmd: process.env.PYTORCH_BIN,
+ gpu: true,
+ },
+ tensorflow: {
+ cmd: process.env.TENSORFLOW_BIN,
+ gpu: true,
+ },
+ python: {
+ cmd: process.env.PYTHON_BIN,
+ gpu: false,
+ },
+ bash: {
+ cmd: process.env.BASH_BIN || '/bin/bash',
+ gpu: false,
+ }
+ perl: {
+ cmd: process.env.PERL_BIN || '/usr/bin/perl',
+ gpu: false,
+ }
+} \ No newline at end of file
diff --git a/app/relay/modules/index.js b/app/relay/modules/index.js
new file mode 100644
index 0000000..65ec75c
--- /dev/null
+++ b/app/relay/modules/index.js
@@ -0,0 +1,13 @@
+import pix2pix from './pix2pix'
+// import pix2pixhd from './pix2pixhd'
+import samplernn from './samplernn'
+import test from './test'
+// torch-warp?
+// audio style transfer?
+// cyclegan?
+export default {
+ pix2pix,
+ // pix2pixhd,
+ samplernn,
+ test,
+} \ No newline at end of file
diff --git a/app/relay/modules/pix2pix.js b/app/relay/modules/pix2pix.js
new file mode 100644
index 0000000..3727964
--- /dev/null
+++ b/app/relay/modules/pix2pix.js
@@ -0,0 +1,71 @@
+import path from 'path'
+
+const name = 'pix2pix'
+const cwd = process.env.PIX2PIX_CWD || path.join(process.env.HOME, 'code/' + name + '/')
+
+const dataset = {
+ type: 'pytorch',
+ script: 'datasets/combine_A_and_B.py',
+ params: (task) => {
+ }
+// python datasets/combine_A_and_B.py \
+// --fold_A /home/lens/Desktop/thumbs/woodscaled_4/A \
+// --fold_B /home/lens/Desktop/thumbs/woodscaled_4/B \
+// --fold_AB datasets/woodscaled_4/
+}
+const train = {
+ type: 'pytorch',
+ script: 'train.py',
+ params: (task) => {
+ },
+// python train.py \
+// --dataroot "./datasets/$dataset" \
+// --name "$dataset" \
+// --model pix2pix \
+// --loadSize 264 \
+// --fineSize 256 \
+// --which_model_netG unet_256 \
+// --which_direction AtoB \
+// --lambda_B 100 \
+// --dataset_mode aligned \
+// --epoch_count $epochs \
+// --which_epoch latest \
+// --continue_train \
+// --no_lsgan --norm batch --pool_size 0
+}
+const generate = {
+ type: 'pytorch',
+ script: 'generate.py',
+ params: (task) => {
+ },
+}
+const live = {
+ type: 'pytorch',
+ script: 'live-mogrify.py',
+ params: (task) => {
+ },
+ // python live-mogrify.py \
+ // --dataroot "./sequences/$sequence" \
+ // --start_img "./sequences/$sequence/frame_00001.png" \
+ // --experiment "$checkpoint" \
+ // --name "$checkpoint" \
+ // --recursive --recursive-frac 0.1 \
+ // --sequence --sequence-frac 0.3 \
+ // --process-frac 0.5 \
+ // --transition \
+ // --transition-min 0.05 \
+ // --how_many 100000 --transition-period 1000 \
+ // --loadSize 256 --fineSize 256 \
+ // --just-copy --poll_delay 0.09 \
+ // --model test --which_model_netG unet_256 \
+ // --which_direction AtoB --dataset_mode recursive \
+ // --which_epoch latest \
+ // --norm batch
+}
+
+export default {
+ name, cwd,
+ activities: {
+ dataset, train, generate, live,
+ }
+}
diff --git a/app/relay/modules/pix2pixhd.js b/app/relay/modules/pix2pixhd.js
new file mode 100644
index 0000000..9aa30d0
--- /dev/null
+++ b/app/relay/modules/pix2pixhd.js
@@ -0,0 +1,5 @@
+import path from 'path'
+
+export default {
+ enabled: false,
+} \ No newline at end of file
diff --git a/app/relay/modules/samplernn.js b/app/relay/modules/samplernn.js
new file mode 100644
index 0000000..4181a32
--- /dev/null
+++ b/app/relay/modules/samplernn.js
@@ -0,0 +1,61 @@
+import path from 'path'
+
+const name = 'samplernn'
+const cwd = process.env.TEST_CWD || path.join(process.env.HOME, 'code/' + name + '/')
+
+const fetch = {
+ type: 'perl',
+ script: 'get.pl',
+ params: (task) => {
+ }
+ // perl get.pl url
+}
+const dataset = {
+ type: 'perl',
+ script: 'dataset.pl',
+ params: (task) => {
+ }
+ // perl dataset.pl filename.flac
+}
+const train = {
+ type: 'pytorch',
+ script: 'train.py',
+ params: (task) => {
+ },
+ onComplete: publish,
+ // python train.py \
+ // --exp $checkpoint_name --dataset $dataset_name \
+ // --frame_sizes 8 2 --n_rnn 2 \
+ // --sample_length $sample_length \
+ // --n_samples $n_samples \
+ // --keep_old_checkpoints False \
+ // --epoch_limit $epoch_limit \
+}
+const generate = {
+ type: 'pytorch',
+ script: 'generate.py',
+ params: (task) => {
+ },
+ onComplete: publish,
+ // python generate.py \
+ // --exp $checkpoint_name --dataset $dataset_name \
+ // --frame_sizes 8 2 --n_rnn 2 \
+ // --sample_length $sample_length \
+ // --n_samples $n_samples \
+ // --keep_old_checkpoints False \
+ // --epoch_limit $epoch_limit \
+}
+const publish = {
+ type: 'perl',
+ script: 'latest.pl',
+ params: (task) => {
+ }
+}
+// after train and generate, run perl latest.pl -l $checkpoint_name
+
+export default {
+ name, cwd,
+ activities: {
+ dataset, train, generate,
+ }
+}
diff --git a/app/relay/modules/test.js b/app/relay/modules/test.js
new file mode 100644
index 0000000..bfac514
--- /dev/null
+++ b/app/relay/modules/test.js
@@ -0,0 +1,36 @@
+import path from 'path'
+
+const name = 'test'
+const cwd = process.env.TEST_CWD || './test/module/'
+
+const dataset = {
+ type: 'perl',
+ script: 'test.pl',
+ params: (task) => {
+ }
+}
+const train = {
+ type: 'perl',
+ script: 'test.pl',
+ params: (task) => {
+ }
+}
+const generate = {
+ type: 'perl',
+ script: 'test.pl',
+}
+const render = {
+ type: 'perl',
+ script: 'test.pl',
+}
+const live = {
+ type: 'pytorch',
+ script: 'test.py',
+}
+
+export default {
+ name, cwd,
+ activities: {
+ dataset, train, generate, render, live,
+ }
+}
diff --git a/app/relay/runner.js b/app/relay/runner.js
new file mode 100644
index 0000000..caa2ded
--- /dev/null
+++ b/app/relay/runner.js
@@ -0,0 +1,68 @@
+// monitors which process is currently running
+// kills it if need be.... murder
+
+import { spawn } from 'child_process'
+import interpreters from './interpreters'
+import modules from './modules'
+import { kill } from 'tree-kill'
+
+var state = {
+ current_cpu_task: null,
+ current_gpu_task: null,
+}
+
+export function get_current_cpu_task(){
+ return state.current_cpu_task
+}
+
+export function get_current_gpu_task(){
+ return state.current_gpu_task
+}
+
+export function build_params(module, task) {
+ const activity = module.activities[task.activity]
+ const interpreter = interpreters[activity.type]
+ if (typeof activity.params === 'function') {
+ params = activity.params(task)
+ }
+ else {
+ const opt = JSON.parse(task.opt)
+ const opt_params = Object.keys(opt).map(key => {
+ const flag = '--' + key.replace(/-/g, '_')
+ const value = opt[key]
+ if (value === 'true') {
+ return [flag]
+ }
+ return [flag, value]
+ }).reduce((acc, cur) => acc.concat(cur), [])
+ params = [ activity.script ].concat(activity.params || []).concat(opt_params)
+ }
+ return {
+ activity,
+ params
+ }
+}
+
+export function run_task(module_name, task){
+ const module = modules['module_name']
+ if (! module) throw new Error("No such module")
+ const { activity, interpreter, params } = build_params(module, task)
+ console.log('running task', activity.name)
+ console.log(activity.interpreter, params)
+ const subprocess = spawn(activity.interpreter, params)
+ if (activity.gpu) {
+ state.current_gpu_task = subprocess
+ } else {
+ state.current_cpu_task = subprocess
+ }
+ subprocess.on('error', (err) => {
+ console.log('process error', subprocess.pid, err)
+ })
+ subprocess.on('close', () => {
+ console.log('process ended', subprocess.pid)
+ })
+}
+
+export function kill_task(subprocess){
+ kill(subprocess.pid)
+} \ No newline at end of file