3.17. Working with Camera and NetworksΒΆ

This notebook explores using a webcamera with a network.

In [1]:
from conx.widgets import CameraWidget
import conx as cx
Using Theano backend.
Conx, version 3.6.0
In [2]:
camera = CameraWidget()
In [3]:
camera
In [4]:
image = camera.get_image()
image
Out[4]:
_images/Camera_4_0.png
In [5]:
image.save("camera.jpg")
In [6]:
data = camera.get_data()
In [7]:
data.shape
Out[7]:
(240, 320, 3)
In [2]:
net = cx.Network("Camera Network")
net.add(cx.ImageLayer("camera", (240, 320), 3),
        cx.Conv2DLayer("conv2d", 32, (3,3)),
        cx.MaxPool2DLayer("maxpool", (2,2)),
        cx.FlattenLayer("flatten"),
        cx.Layer("output", 10))
net.connect()
net.compile(error="mse", optimizer="adam")
In [10]:
net.dataset.append(data, cx.to_categorical(1, 10))
In [11]:
net.dashboard()
In [12]:
net.picture(camera.get_data())
Out[12]:
Layer: output (output) output range: (-Infinity, +Infinity) shape = (10,) Keras class = DenseoutputWeights from flatten to output output/kernel:0 has shape (605472, 10) output/bias:0 has shape (10,)Layer: flatten (hidden) output range: (-Infinity, +Infinity) Keras class = FlattenflattenWeights from maxpool to flattenLayer: maxpool (hidden) output range: (-Infinity, +Infinity) Keras class = MaxPooling2Dmaxpool320Weights from conv2d to maxpoolLayer: conv2d (hidden) output range: (-Infinity, +Infinity) Keras class = Conv2Dconv2d320Weights from camera to conv2d conv2d/kernel:0 has shape (3, 3, 3, 32) conv2d/bias:0 has shape (32,)Layer: camera (input) output range: (0.0, 1.0) shape = (240, 320, 3) Keras class = InputcameraCamera Network