Skip to content

Commit

Permalink
update demos to use protobuf format models
Browse files Browse the repository at this point in the history
  • Loading branch information
transcranial committed Nov 10, 2017
1 parent 493ff3b commit 347d3ef
Show file tree
Hide file tree
Showing 15 changed files with 452 additions and 793 deletions.
32 changes: 13 additions & 19 deletions demos/src/components/models/ImdbBidirectionalLstm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,12 @@ import findIndex from 'lodash/findIndex'
import ops from 'ndarray-ops'
import Tensor from '../../../../src/Tensor'
const MODEL_FILEPATHS_DEV = {
model: '/demos/data/imdb_bidirectional_lstm/imdb_bidirectional_lstm.json',
weights: '/demos/data/imdb_bidirectional_lstm/imdb_bidirectional_lstm_weights.buf',
metadata: '/demos/data/imdb_bidirectional_lstm/imdb_bidirectional_lstm_metadata.json'
const MODEL_CONFIG = {
filepath:
process.env.NODE_ENV === 'production'
? 'https://transcranial.github.io/keras-js-demos-data/imdb_bidirectional_lstm/imdb_bidirectional_lstm.bin'
: '/demos/data/imdb_bidirectional_lstm/imdb_bidirectional_lstm.bin'
}
const MODEL_FILEPATHS_PROD = {
model: 'https://transcranial.github.io/keras-js-demos-data/imdb_bidirectional_lstm/imdb_bidirectional_lstm.json',
weights:
'https://transcranial.github.io/keras-js-demos-data/imdb_bidirectional_lstm/imdb_bidirectional_lstm_weights.buf',
metadata:
'https://transcranial.github.io/keras-js-demos-data/imdb_bidirectional_lstm/imdb_bidirectional_lstm_metadata.json'
}
const MODEL_CONFIG = { filepaths: process.env.NODE_ENV === 'production' ? MODEL_FILEPATHS_PROD : MODEL_FILEPATHS_DEV }
const ADDITIONAL_DATA_FILEPATHS_DEV = {
wordIndex: '/demos/data/imdb_bidirectional_lstm/imdb_dataset_word_index_top20000.json',
Expand All @@ -102,14 +95,14 @@ const INDEX_FROM = 3
// network layers
const ARCHITECTURE_DIAGRAM_LAYERS = [
{ name: 'embedding_2', className: 'Embedding', details: '200 time steps, dims 20000 -> 64' },
{ name: 'embedding_1', className: 'Embedding', details: '200 time steps, dims 20000 -> 64' },
{
name: 'bidirectional_2',
name: 'bidirectional_1',
className: 'Bidirectional [LSTM]',
details: '200 time steps, dims 64 -> 32, concat merge, tanh activation, hard sigmoid recurrent activation'
},
{ name: 'dropout_2', className: 'Dropout', details: 'p=0.5 (active during training)' },
{ name: 'dense_2', className: 'Dense', details: 'output dims 1, sigmoid activation' }
{ name: 'dropout_1', className: 'Dropout', details: 'p=0.5 (active during training)' },
{ name: 'dense_1', className: 'Dense', details: 'output dims 1, sigmoid activation' }
]
export default {
Expand Down Expand Up @@ -172,6 +165,7 @@ export default {
this.inputText = ''
this.inputTextParsed = []
this.output = new Float32Array(1)
this.isSampleText = false
},
loadAdditionalData: function() {
this.modelLoading = true
Expand Down Expand Up @@ -253,9 +247,9 @@ export default {
})
}, 200),
stepwiseCalc: function() {
const fcLayer = this.model.modelLayersMap.get('dense_2')
const forwardHiddenStates = this.model.modelLayersMap.get('bidirectional_2').forwardLayer.hiddenStateSequence
const backwardHiddenStates = this.model.modelLayersMap.get('bidirectional_2').backwardLayer.hiddenStateSequence
const fcLayer = this.model.modelLayersMap.get('dense_1')
const forwardHiddenStates = this.model.modelLayersMap.get('bidirectional_1').forwardLayer.hiddenStateSequence
const backwardHiddenStates = this.model.modelLayersMap.get('bidirectional_1').backwardLayer.hiddenStateSequence
const forwardDim = forwardHiddenStates.tensor.shape[1]
const backwardDim = backwardHiddenStates.tensor.shape[1]
Expand Down
15 changes: 5 additions & 10 deletions demos/src/components/models/InceptionV3.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,12 @@ import * as utils from '../../utils'
import { IMAGE_URLS } from '../../data/sample-image-urls'
import { ARCHITECTURE_DIAGRAM, ARCHITECTURE_CONNECTIONS } from '../../data/inception-v3-arch'
const MODEL_FILEPATHS_DEV = {
model: '/demos/data/inception_v3/inception_v3.json',
weights: '/demos/data/inception_v3/inception_v3_weights.buf',
metadata: '/demos/data/inception_v3/inception_v3_metadata.json'
const MODEL_CONFIG = {
filepath:
process.env.NODE_ENV === 'production'
? 'https://transcranial.github.io/keras-js-demos-data/inception_v3/inception_v3.bin'
: '/demos/data/inception_v3/inception_v3.bin'
}
const MODEL_FILEPATHS_PROD = {
model: 'https://transcranial.github.io/keras-js-demos-data/inception_v3/inception_v3.json',
weights: 'https://transcranial.github.io/keras-js-demos-data/inception_v3/inception_v3_weights.buf',
metadata: 'https://transcranial.github.io/keras-js-demos-data/inception_v3/inception_v3_metadata.json'
}
const MODEL_CONFIG = { filepaths: process.env.NODE_ENV === 'production' ? MODEL_FILEPATHS_PROD : MODEL_FILEPATHS_DEV }
export default {
props: ['hasWebGL'],
Expand Down
15 changes: 5 additions & 10 deletions demos/src/components/models/MnistAcgan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,12 @@ import * as utils from '../../utils'
import filter from 'lodash/filter'
import { ARCHITECTURE_DIAGRAM, ARCHITECTURE_CONNECTIONS } from '../../data/mnist-acgan-arch'
const MODEL_FILEPATHS_DEV = {
model: '/demos/data/mnist_acgan/mnist_acgan.json',
weights: '/demos/data/mnist_acgan/mnist_acgan_weights.buf',
metadata: '/demos/data/mnist_acgan/mnist_acgan_metadata.json'
const MODEL_CONFIG = {
filepath:
process.env.NODE_ENV === 'production'
? 'https://transcranial.github.io/keras-js-demos-data/mnist_acgan/mnist_acgan.bin'
: '/demos/data/mnist_acgan/mnist_acgan.bin'
}
const MODEL_FILEPATHS_PROD = {
model: 'https://transcranial.github.io/keras-js-demos-data/mnist_acgan/mnist_acgan.json',
weights: 'https://transcranial.github.io/keras-js-demos-data/mnist_acgan/mnist_acgan_weights.buf',
metadata: 'https://transcranial.github.io/keras-js-demos-data/mnist_acgan/mnist_acgan_metadata.json'
}
const MODEL_CONFIG = { filepaths: process.env.NODE_ENV === 'production' ? MODEL_FILEPATHS_PROD : MODEL_FILEPATHS_DEV }
export default {
props: ['hasWebGL'],
Expand Down
15 changes: 5 additions & 10 deletions demos/src/components/models/MnistCnn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,12 @@ import debounce from 'lodash/debounce'
import range from 'lodash/range'
import * as utils from '../../utils'
const MODEL_FILEPATHS_DEV = {
model: '/demos/data/mnist_cnn/mnist_cnn.json',
weights: '/demos/data/mnist_cnn/mnist_cnn_weights.buf',
metadata: '/demos/data/mnist_cnn/mnist_cnn_metadata.json'
const MODEL_CONFIG = {
filepath:
process.env.NODE_ENV === 'production'
? 'https://transcranial.github.io/keras-js-demos-data/mnist_cnn/mnist_cnn.bin'
: '/demos/data/mnist_cnn/mnist_cnn.bin'
}
const MODEL_FILEPATHS_PROD = {
model: 'https://transcranial.github.io/keras-js-demos-data/mnist_cnn/mnist_cnn.json',
weights: 'https://transcranial.github.io/keras-js-demos-data/mnist_cnn/mnist_cnn_weights.buf',
metadata: 'https://transcranial.github.io/keras-js-demos-data/mnist_cnn/mnist_cnn_metadata.json'
}
const MODEL_CONFIG = { filepaths: process.env.NODE_ENV === 'production' ? MODEL_FILEPATHS_PROD : MODEL_FILEPATHS_DEV }
const LAYER_DISPLAY_CONFIG = {
conv2d_1: { heading: '32 3x3 filters, padding valid, 1x1 strides', scalingFactor: 2 },
Expand Down
33 changes: 14 additions & 19 deletions demos/src/components/models/MnistVae.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,21 @@
import _ from 'lodash'
import * as utils from '../../utils'
const MODEL_FILEPATHS_DEV = {
model: '/demos/data/mnist_vae/mnist_vae.json',
weights: '/demos/data/mnist_vae/mnist_vae_weights.buf',
metadata: '/demos/data/mnist_vae/mnist_vae_metadata.json'
const MODEL_CONFIG = {
filepath:
process.env.NODE_ENV === 'production'
? 'https://transcranial.github.io/keras-js-demos-data/mnist_vae/mnist_vae.bin'
: '/demos/data/mnist_vae/mnist_vae.bin'
}
const MODEL_FILEPATHS_PROD = {
model: 'https://transcranial.github.io/keras-js-demos-data/mnist_vae/mnist_vae.json',
weights: 'https://transcranial.github.io/keras-js-demos-data/mnist_vae/mnist_vae_weights.buf',
metadata: 'https://transcranial.github.io/keras-js-demos-data/mnist_vae/mnist_vae_metadata.json'
}
const MODEL_CONFIG = { filepaths: process.env.NODE_ENV === 'production' ? MODEL_FILEPATHS_PROD : MODEL_FILEPATHS_DEV }
const LAYER_DISPLAY_CONFIG = {
dense_19: { heading: 'input dimensions = 2, output dimensions = 128, ReLU activation', scalingFactor: 2 },
dense_20: { heading: 'ReLU activation, output dimensions = 25088 (64 x 14 x 14)', scalingFactor: 2 },
reshape_7: { heading: '', scalingFactor: 2 },
conv2d_transpose_19: { heading: '64 3x3 filters, padding same, 1x1 strides, ReLU activation', scalingFactor: 2 },
conv2d_transpose_20: { heading: '64 3x3 filters, padding same, 1x1 strides, ReLU activation', scalingFactor: 2 },
conv2d_transpose_21: { heading: '64 2x2 filters, padding valid, 2x2 strides, ReLU activation', scalingFactor: 2 },
conv2d_15: { heading: '1 2x2 filters, padding same, 1x1 strides, sigmoid activation', scalingFactor: 2 }
dense_6: { heading: 'input dimensions = 2, output dimensions = 128, ReLU activation', scalingFactor: 2 },
dense_7: { heading: 'ReLU activation, output dimensions = 25088 (64 x 14 x 14)', scalingFactor: 2 },
reshape_2: { heading: '', scalingFactor: 2 },
conv2d_transpose_4: { heading: '64 3x3 filters, padding same, 1x1 strides, ReLU activation', scalingFactor: 2 },
conv2d_transpose_5: { heading: '64 3x3 filters, padding same, 1x1 strides, ReLU activation', scalingFactor: 2 },
conv2d_transpose_6: { heading: '64 2x2 filters, padding valid, 2x2 strides, ReLU activation', scalingFactor: 2 },
conv2d_6: { heading: '1 2x2 filters, padding same, 1x1 strides, sigmoid activation', scalingFactor: 2 }
}
export default {
Expand Down Expand Up @@ -207,9 +202,9 @@ export default {
{ leading: true, trailing: true }
),
runModel: function() {
const inputData = { input_7: new Float32Array(this.inputCoordinates) }
const inputData = { input_2: new Float32Array(this.inputCoordinates) }
this.model.predict(inputData).then(outputData => {
this.output = outputData['conv2d_15']
this.output = outputData['conv2d_6']
this.drawOutput()
this.getIntermediateOutputs()
})
Expand Down
15 changes: 5 additions & 10 deletions demos/src/components/models/Resnet50.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,12 @@ import * as utils from '../../utils'
import { IMAGE_URLS } from '../../data/sample-image-urls'
import { ARCHITECTURE_DIAGRAM, ARCHITECTURE_CONNECTIONS } from '../../data/resnet50-arch'
const MODEL_FILEPATHS_DEV = {
model: '/demos/data/resnet50/resnet50.json',
weights: '/demos/data/resnet50/resnet50_weights.buf',
metadata: '/demos/data/resnet50/resnet50_metadata.json'
const MODEL_CONFIG = {
filepath:
process.env.NODE_ENV === 'production'
? 'https://transcranial.github.io/keras-js-demos-data/resnet50/resnet50.bin'
: '/demos/data/resnet50/resnet50.bin'
}
const MODEL_FILEPATHS_PROD = {
model: 'https://transcranial.github.io/keras-js-demos-data/resnet50/resnet50.json',
weights: 'https://transcranial.github.io/keras-js-demos-data/resnet50/resnet50_weights.buf',
metadata: 'https://transcranial.github.io/keras-js-demos-data/resnet50/resnet50_metadata.json'
}
const MODEL_CONFIG = { filepaths: process.env.NODE_ENV === 'production' ? MODEL_FILEPATHS_PROD : MODEL_FILEPATHS_DEV }
export default {
props: ['hasWebGL'],
Expand Down
15 changes: 5 additions & 10 deletions demos/src/components/models/SqueezenetV1.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,12 @@ import * as utils from '../../utils'
import { IMAGE_URLS } from '../../data/sample-image-urls'
import { ARCHITECTURE_DIAGRAM, ARCHITECTURE_CONNECTIONS } from '../../data/squeezenet-v1.1-arch'
const MODEL_FILEPATHS_DEV = {
model: '/demos/data/squeezenet_v1.1/squeezenet_v1.1.json',
weights: '/demos/data/squeezenet_v1.1/squeezenet_v1.1_weights.buf',
metadata: '/demos/data/squeezenet_v1.1/squeezenet_v1.1_metadata.json'
const MODEL_CONFIG = {
filepath:
process.env.NODE_ENV === 'production'
? 'https://transcranial.github.io/keras-js-demos-data/squeezenet_v1.1/squeezenet_v1.1.bin'
: '/demos/data/squeezenet_v1.1/squeezenet_v1.1.bin'
}
const MODEL_FILEPATHS_PROD = {
model: 'https://transcranial.github.io/keras-js-demos-data/squeezenet_v1.1/squeezenet_v1.1.json',
weights: 'https://transcranial.github.io/keras-js-demos-data/squeezenet_v1.1/squeezenet_v1.1_weights.buf',
metadata: 'https://transcranial.github.io/keras-js-demos-data/squeezenet_v1.1/squeezenet_v1.1_metadata.json'
}
const MODEL_CONFIG = { filepaths: process.env.NODE_ENV === 'production' ? MODEL_FILEPATHS_PROD : MODEL_FILEPATHS_DEV }
export default {
props: ['hasWebGL'],
Expand Down
Loading

0 comments on commit 347d3ef

Please sign in to comment.