Working with Camera and Networks

In [1]:
from conx.widgets import CameraWidget
from conx import Network
from conx.layers import *
Using Theano backend.
conx, version 3.5.2
In [2]:
camera = CameraWidget()
In [3]:
camera
In [4]:
image = camera.get_image()
image
Out[4]:
In [5]:
image.save("nips91.jpg")
In [6]:
data = camera.get_data()
In [7]:
data.shape
Out[7]:
(240, 320, 3)
In [8]:
net = Network("Camera Network")
net.add(ImageLayer("camera", (240, 320), 3))
net.add(Conv2DLayer("conv2d", 32, (3,3)))
net.add(MaxPool2DLayer("maxpool", (2,2)))
net.add(FlattenLayer("flatten"))
net.add(Layer("output", 10))
net.connect()
net.compile(error="mse", optimizer="adam")
In [9]:
net.dataset.add(data, to_categorical(1, 10))
In [10]:
net.dashboard()
In [11]:
net.snapshot(camera.get_data())
Out[11]:
Camera NetworkLayer: output (output) shape = (10,) Keras class = DenseoutputWeights from flatten to output output/kernel has shape (605472, 10) output/bias has shape (10,)Layer: flatten (hidden) Keras class = FlattenflattenWeights from maxpool to flattenLayer: maxpool (hidden) Keras class = MaxPooling2Dmaxpool320Weights from conv2d to maxpoolLayer: conv2d (hidden) Keras class = Conv2Dconv2d320Weights from camera to conv2d conv2d/kernel has shape (3, 3, 3, 32) conv2d/bias has shape (32,)Layer: camera (input) shape = (240, 320, 3) Keras class = Inputcamera

This should work:

In [33]:
camera.observe(lambda widget: net.propagate(image2aray(camera.get_image())))
In [30]:
inputs = []

camera.observe(lambda widget: inputs.append(camera.get_image()))
In [31]:
for image in inputs:
    display(array2image(image))
In [32]:
inputs
Out[32]:
[]
In [27]:
camera.observe(lambda widget: net.propagate(image2array(camera.get_image())), "value")
In [34]:
camera.observe(lambda *args, **kwargs: print(args, kwargs))