summaryrefslogtreecommitdiff
path: root/app/client/modules/biggan
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-12-18 21:13:05 +0100
committerJules Laplace <julescarbon@gmail.com>2019-12-18 21:13:05 +0100
commitfe8ab6133a31284d94944f5d75da9d6ad2b2bdb9 (patch)
tree6b73b14bd88b64868d776b481d2aca0feb453c9c /app/client/modules/biggan
parent3a432e15399bd756cdeef376b46ae2968559790c (diff)
adding biggan
Diffstat (limited to 'app/client/modules/biggan')
-rw-r--r--app/client/modules/biggan/biggan.actions.js12
-rw-r--r--app/client/modules/biggan/biggan.module.js7
-rw-r--r--app/client/modules/biggan/biggan.reducer.js43
-rw-r--r--app/client/modules/biggan/biggan.tasks.js20
-rw-r--r--app/client/modules/biggan/index.js37
-rw-r--r--app/client/modules/biggan/views/biggan.live.js180
6 files changed, 299 insertions, 0 deletions
diff --git a/app/client/modules/biggan/biggan.actions.js b/app/client/modules/biggan/biggan.actions.js
new file mode 100644
index 0000000..188a0d8
--- /dev/null
+++ b/app/client/modules/biggan/biggan.actions.js
@@ -0,0 +1,12 @@
+import uuidv1 from 'uuid/v1'
+
+import socket from '../../socket'
+import types from '../../types'
+
+import * as datasetLoader from '../../dataset/dataset.loader'
+
+import actions from '../../actions'
+
+import util from '../../util'
+
+import bigganModule from './biggan.module'
diff --git a/app/client/modules/biggan/biggan.module.js b/app/client/modules/biggan/biggan.module.js
new file mode 100644
index 0000000..6407f61
--- /dev/null
+++ b/app/client/modules/biggan/biggan.module.js
@@ -0,0 +1,7 @@
+const bigganModule = {
+ name: 'biggan',
+ displayName: 'BigGAN',
+ datatype: 'video',
+}
+
+export default bigganModule
diff --git a/app/client/modules/biggan/biggan.reducer.js b/app/client/modules/biggan/biggan.reducer.js
new file mode 100644
index 0000000..a0c9842
--- /dev/null
+++ b/app/client/modules/biggan/biggan.reducer.js
@@ -0,0 +1,43 @@
+import types from '../../types'
+import datasetReducer from '../../dataset/dataset.reducer'
+
+const bigganInitialState = {
+ loading: true,
+ progress: { i: 0, n: 0 },
+ error: null,
+ folder_id: 0,
+ data: null,
+ results: null,
+ checkpoint: {
+ name: '',
+ sequenceCount: 0,
+ datasetCount: 0,
+ }
+}
+
+const bigganReducer = (state = bigganInitialState, action) => {
+ if (action.data && action.data.module === 'biggan') {
+ state = datasetReducer(state, action)
+ }
+
+ switch (action.type) {
+ case types.biggan.load_results:
+ return {
+ ...state,
+ results: action.results,
+ }
+ case types.file.destroy:
+ console.log('file destroy', state.results)
+ return {
+ ...state,
+ results: {
+ ...state.results,
+ files: state.results.files.filter(f => f.id !== action.data.id)
+ }
+ }
+ default:
+ return state
+ }
+}
+
+export default bigganReducer
diff --git a/app/client/modules/biggan/biggan.tasks.js b/app/client/modules/biggan/biggan.tasks.js
new file mode 100644
index 0000000..827add5
--- /dev/null
+++ b/app/client/modules/biggan/biggan.tasks.js
@@ -0,0 +1,20 @@
+import uuidv1 from 'uuid/v1'
+
+import socket from '../../socket'
+import types from '../../types'
+
+import actions from '../../actions'
+
+import module from './biggan.module'
+
+export const live_task = (opt) => dispatch => {
+ const task = {
+ module: module.name,
+ activity: 'live',
+ dataset: 'biggan',
+ opt
+ }
+ console.log(task)
+ console.log('add live task')
+ return actions.queue.add_task(task)
+}
diff --git a/app/client/modules/biggan/index.js b/app/client/modules/biggan/index.js
new file mode 100644
index 0000000..6c94008
--- /dev/null
+++ b/app/client/modules/biggan/index.js
@@ -0,0 +1,37 @@
+import { h, Component } from 'preact'
+import { Route, Link } from 'react-router-dom'
+
+import actions from '../../actions'
+
+import util from '../../util'
+
+import BigGANLive from './views/biggan.live'
+
+class router {
+ componentWillMount(){
+ actions.system.changeTool('biggan')
+ document.body.style.backgroundImage = 'linear-gradient(' + (util.randint(40)+40) + 'deg, #dfe, #def)'
+ }
+ componentWillReceiveProps(){
+ actions.system.changeTool('biggan')
+ document.body.style.backgroundImage = 'linear-gradient(' + (util.randint(40)+40) + 'deg, #dfe, #def)'
+ }
+ render(){
+ return (
+ <section>
+ <Route exact path='/biggan/live/' component={BigGANLive} />
+ </section>
+ )
+ }
+}
+
+function links(){
+ return [
+ { url: '/biggan/live/', name: 'live' },
+ ]
+}
+
+export default {
+ name: 'biggan',
+ router, links,
+}
diff --git a/app/client/modules/biggan/views/biggan.live.js b/app/client/modules/biggan/views/biggan.live.js
new file mode 100644
index 0000000..ba96ff2
--- /dev/null
+++ b/app/client/modules/biggan/views/biggan.live.js
@@ -0,0 +1,180 @@
+import { h, Component } from 'preact'
+import { bindActionCreators } from 'redux'
+import { connect } from 'react-redux'
+
+import {
+ ParamGroup, Param, Player, Group,
+ Slider, SelectGroup, Select, TextInput, Button, Loading
+} from '../../../common/'
+
+import { startRecording, stopRecording, saveFrame, toggleFPS } from '../../../live/player'
+
+import * as liveActions from '../../../live/live.actions'
+import * as queueActions from '../../../queue/queue.actions'
+import * as bigganTasks from '../biggan.tasks'
+import * as bigganActions from '../biggan.actions'
+
+class BigGANLive extends Component {
+ constructor(props) {
+ super()
+ }
+ start(){
+ console.log(this.props.opt)
+ console.log('starting up!')
+ this.props.actions.tasks.live_task({
+ folder_id: this.props.biggan.data.resultsFolder.id,
+ })
+ }
+ interrupt(){
+ this.props.actions.queue.stop_task('gpu')
+ }
+ render() {
+ const { biggan } = this.props
+ // if (biggan.loading) {
+ // return <Loading progress={biggan.progress} />
+ // }
+ return (
+ <div className='app live centered'>
+ <div className='row'>
+ <div className='column'>
+ <Player width={512} height={512} fullscreen={this.props.fullscreen} />
+ </div>
+ <div className='params column audioParams'>
+ <Group>
+ {this.renderRestartButton()}
+ </Group>
+
+ <ParamGroup
+ title={"Latent"}
+ name='latent'
+ >
+ <Button
+ title={"Shuffle"}
+ onClick={() => {}}
+ >{"Latent"}</Button>
+ <Slider live
+ name='latent_update_speed'
+ title={"Update Speed"}
+ min={0} max={1} type='float'
+ />
+ </ParamGroup>
+
+ <ParamGroup
+ title={"Label"}
+ name='label'
+ >
+ <Slider live
+ name='label_class_count'
+ title={"Classes"}
+ min={1} max={10} type='int'
+ />
+ <Button
+ title={"Shuffle"}
+ onClick={() => {}}
+ >{"Label"}</Button>
+ <Slider live
+ name='label_lerp_speed'
+ title={"Interpolation Speed"}
+ min={0} max={1} type='float'
+ />
+ </ParamGroup>
+
+ <ParamGroup
+ title={"Orbit"}
+ name='orbit'
+ >
+ <Slider live
+ name='orbit_speed'
+ title={"Orbit speed"}
+ min={0} max={1} type='float'
+ />
+ <Slider live
+ name='orbit_scale'
+ title={"Radius"}
+ min={0} max={0.25} type='float'
+ />
+ <Button
+ title={"Noise"}
+ onClick={() => {}}
+ >{"Spin"}</Button>
+ <Slider live
+ name='orbit_update_speed'
+ title={"Update Speed"}
+ min={0} max={1} type='float'
+ />
+ </ParamGroup>
+
+ </div>
+ </div>
+ </div>
+ )
+ }
+ renderRestartButton(){
+ // console.log(this.props.runner.gpu)
+ const { i18n } = this.props
+ if (this.props.runner.gpu.status === 'IDLE') {
+ return (
+ <Button
+ title={i18n.gpu.idle}
+ onClick={() => this.start()}
+ >{i18n.gpu.start}</Button>
+ )
+ }
+ if (this.props.runner.gpu.task.module !== 'pix2pixhd') {
+ return (
+ <Button
+ title={i18n.gpu.busy}
+ onClick={() => this.interrupt()}
+ >{i18n.gpu.interrupt}</Button>
+ )
+ }
+ if (! this.props.opt.processing) {
+ return (
+ <div>
+ <Button
+ title={i18n.gpu.not_processing}
+ onClick={this.togglePlaying}
+ >{i18n.gpu.restart}</Button>
+ <Button
+ title={i18n.gpu.busy}
+ onClick={() => this.interrupt()}
+ >{i18n.gpu.interrupt}</Button>
+ </div>
+ )
+ }
+ return (
+ <div>
+ <Button
+ title={i18n.gpu.processing}
+ onClick={this.togglePlaying}
+ >{i18n.gpu.stop}</Button>
+ <Button
+ title={i18n.gpu.busy}
+ onClick={() => this.interrupt()}
+ >{i18n.gpu.interrupt}</Button>
+ </div>
+ )
+ }
+}
+
+
+const mapStateToProps = state => ({
+ last_message: state.live.last_message,
+ fullscreen: state.live.fullscreen,
+ opt: state.live.opt,
+ frame: state.live.frame,
+ runner: state.system.runner,
+ i18n: state.system.i18n.strings,
+ biggan: state.module.biggan,
+})
+
+const mapDispatchToProps = (dispatch, ownProps) => ({
+ actions: {
+ live: bindActionCreators(liveActions, dispatch),
+ queue: bindActionCreators(queueActions, dispatch),
+ biggan: bindActionCreators(bigganActions, dispatch),
+ tasks: bindActionCreators(bigganTasks, dispatch),
+ }
+})
+
+export default connect(mapStateToProps, mapDispatchToProps)(BigGANLive)