Skip to content

Commit

Permalink
move imagenet classes to data folder, refactor util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
transcranial committed Dec 1, 2017
1 parent 0795e3c commit 77d0075
Show file tree
Hide file tree
Showing 9 changed files with 1,218 additions and 1,213 deletions.
4 changes: 2 additions & 2 deletions demos/src/components/common/Imagenet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ import loadImage from 'blueimp-load-image'
import ndarray from 'ndarray'
import ops from 'ndarray-ops'
import resample from 'ndarray-resample'
import * as utils from '../../utils'
import { imagenetUtils } from '../../utils'
import { IMAGE_URLS } from '../../data/sample-image-urls'
import { COLORMAPS } from '../../data/colormaps'
import ModelStatus from './ModelStatus'
Expand Down Expand Up @@ -205,7 +205,7 @@ export default {
}
return empty
}
return utils.imagenetClassesTopK(this.output, 5)
return imagenetUtils.imagenetClassesTopK(this.output, 5)
}
},
Expand Down
4 changes: 2 additions & 2 deletions demos/src/components/models/MnistAcgan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

<script>
import _ from 'lodash'
import * as utils from '../../utils'
import { tensorUtils } from '../../utils'
import { ARCHITECTURE_DIAGRAM, ARCHITECTURE_CONNECTIONS } from '../../data/mnist-acgan-arch'
import ModelStatus from '../common/ModelStatus'
Expand Down Expand Up @@ -220,7 +220,7 @@ export default {
},
drawOutput() {
const ctx = document.getElementById('output-canvas').getContext('2d')
const image = utils.image2Darray(this.output, 28, 28, [0, 0, 0])
const image = tensorUtils.image2Darray(this.output, 28, 28, [0, 0, 0])
ctx.putImageData(image, 0, 0)
// scale up
Expand Down
16 changes: 8 additions & 8 deletions demos/src/components/models/MnistCnn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

<script>
import _ from 'lodash'
import * as utils from '../../utils'
import { mathUtils, tensorUtils } from '../../utils'
import ModelStatus from '../common/ModelStatus'
const MODEL_FILEPATH_PROD = 'https://transcranial.github.io/keras-js-demos-data/mnist_cnn/mnist_cnn.bin'
Expand Down Expand Up @@ -219,7 +219,7 @@ export default {
this.drawing = true
this.strokes.push([])
let points = this.strokes[this.strokes.length - 1]
points.push(utils.getCoordinates(e))
points.push(mathUtils.getCoordinates(e))
},
draw(e) {
if (!this.drawing) return
Expand All @@ -233,7 +233,7 @@ export default {
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height)
let points = this.strokes[this.strokes.length - 1]
points.push(utils.getCoordinates(e))
points.push(mathUtils.getCoordinates(e))
// draw individual strokes
for (let s = 0, slen = this.strokes.length; s < slen; s++) {
Expand All @@ -247,7 +247,7 @@ export default {
// draw points in stroke
// quadratic bezier curve
for (let i = 1, len = points.length; i < len; i++) {
ctx.quadraticCurveTo(...p1, ...utils.getMidpoint(p1, p2))
ctx.quadraticCurveTo(...p1, ...mathUtils.getMidpoint(p1, p2))
p1 = points[i]
p2 = points[i + 1]
}
Expand All @@ -263,7 +263,7 @@ export default {
const ctx = document.getElementById('input-canvas').getContext('2d')
// center crop
const imageDataCenterCrop = utils.centerCrop(ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height))
const imageDataCenterCrop = mathUtils.centerCrop(ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height))
const ctxCenterCrop = document.getElementById('input-canvas-centercrop').getContext('2d')
ctxCenterCrop.canvas.width = imageDataCenterCrop.width
ctxCenterCrop.canvas.height = imageDataCenterCrop.height
Expand Down Expand Up @@ -299,11 +299,11 @@ export default {
if (name === 'input') return
let images = []
if (layer.hasOutput && layer.output && layer.output.tensor.shape.length === 3) {
images = utils.unroll3Dtensor(layer.output.tensor)
images = tensorUtils.unroll3Dtensor(layer.output.tensor)
} else if (layer.hasOutput && layer.output && layer.output.tensor.shape.length === 2) {
images = [utils.image2Dtensor(layer.output.tensor)]
images = [tensorUtils.image2Dtensor(layer.output.tensor)]
} else if (layer.hasOutput && layer.output && layer.output.tensor.shape.length === 1) {
images = [utils.image1Dtensor(layer.output.tensor)]
images = [tensorUtils.image1Dtensor(layer.output.tensor)]
}
outputs.push({ layerClass: layer.layerClass || '', name, images })
})
Expand Down
10 changes: 5 additions & 5 deletions demos/src/components/models/MnistVae.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@

<script>
import _ from 'lodash'
import * as utils from '../../utils'
import { tensorUtils } from '../../utils'
import ModelStatus from '../common/ModelStatus'
const MODEL_FILEPATH_PROD = 'https://transcranial.github.io/keras-js-demos-data/mnist_vae/mnist_vae.bin'
Expand Down Expand Up @@ -250,7 +250,7 @@ export default {
},
drawOutput() {
const ctx = document.getElementById('output-canvas').getContext('2d')
const image = utils.image2Darray(this.output, 28, 28, [0, 0, 0])
const image = tensorUtils.image2Darray(this.output, 28, 28, [0, 0, 0])
ctx.putImageData(image, 0, 0)
// scale up
Expand All @@ -267,11 +267,11 @@ export default {
if (layer.layerClass === 'InputLayer') return
let images = []
if (layer.hasOutput && layer.output && layer.output.tensor.shape.length === 3) {
images = utils.unroll3Dtensor(layer.output.tensor)
images = tensorUtils.unroll3Dtensor(layer.output.tensor)
} else if (layer.hasOutput && layer.output && layer.output.tensor.shape.length === 2) {
images = [utils.image2Dtensor(layer.output.tensor)]
images = [tensorUtils.image2Dtensor(layer.output.tensor)]
} else if (layer.hasOutput && layer.output && layer.output.tensor.shape.length === 1) {
images = [utils.image1Dtensor(layer.output.tensor)]
images = [tensorUtils.image1Dtensor(layer.output.tensor)]
}
outputs.push({ layerClass: layer.layerClass || '', name, images })
})
Expand Down
Loading

0 comments on commit 77d0075

Please sign in to comment.