Skip to content

Commit

Permalink
first progress on inputlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
elggem committed Nov 16, 2016
1 parent 3901882 commit b15ceec
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 15 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,4 @@ ENV/
.ropeproject

# tensorflow data
data/*
output/*
1 change: 1 addition & 0 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mnist/
Binary file added data/hand.m4v
Binary file not shown.
2 changes: 2 additions & 0 deletions inputlayer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .inputlayer import InputLayer
from .opencv import OpenCVInputLayer
23 changes: 23 additions & 0 deletions inputlayer/inputlayer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-

class InputLayer:
"""
Contains the worker thread that uses OpenCV to feed in images and video feeds to TF.
"""

def assertions(self):
assert(42==42)

def __init__(self):
self.assertions()
self.callbacks = []
print ("📸 Input Layer initalized")

def registerCallback(self, region, callback):
##assert callback is a function
self.callbacks.append([region, callback])
print ("📸 callback registered")


def deregisterCallback(self, callback):
raise NotImplementedError()
42 changes: 42 additions & 0 deletions inputlayer/opencv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
import cv2
from . import InputLayer

class OpenCVInputLayer(InputLayer):
"""
Contains the worker thread that uses OpenCV to feed in images and video feeds to TF.
"""

def feedWebcam(self):
cap = cv2.VideoCapture(0)

while(True):
isvalid, frame = cap.read()
if isvalid:
res = cv2.resize(frame,(32, 32), interpolation = cv2.INTER_CUBIC)
gray = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)
self.processFrame(gray)
else:
break

def feedVideo(self, filename):
cap = cv2.VideoCapture(filename)

while(True):
isvalid, frame = cap.read()
if isvalid:
res = cv2.resize(frame,(32, 32), interpolation = cv2.INTER_CUBIC)
gray = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)
self.processFrame(gray)
else:
break

def processFrame(self, frame):
for region, callback in self.callbacks:
x = region[0]
y = region[1]
w = region[2]
h = region[3]
callback(frame[y:y + h, x:x + w])
#iterate callbacks and split into corresponding regions
#triggercallbacks
48 changes: 36 additions & 12 deletions manual_4_stream_input.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,67 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#from sklearn import datasets
from model import StackedAutoEncoder
import matplotlib.pyplot as plt
from inputlayer import OpenCVInputLayer

import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('data/mnist', one_hot=True)
#from tensorflow.examples.tutorials.mnist import input_data
#mnist = input_data.read_data_sets('data/mnist', one_hot=True)

import numpy as np
import model.utils as utils
from os.path import join as pjoin

#utils.start_tensorboard()

train_data = mnist.train.images
import cv2
#utils.start_tensorboard()

print "👉 processed input data!"
#train_data = mnist.train.images
#print "👉 processed input data!"

print "recording summaries to " + utils.get_summary_dir()


models = []

for _ in xrange(4):
models.append(StackedAutoEncoder(
dims=[100, 100],
activations=['linear', 'linear'],
dims=[100],
activations=['linear'],
noise='gaussian',
epoch=[100, 100],
epoch=[10],
loss='rmse',
lr=0.007,
batch_size=150
batch_size=1
))

### Initialize Enqueue thread:
inputlayer = OpenCVInputLayer()

inputlayer.registerCallback([00,00,16,16], models[0].fit)
inputlayer.registerCallback([16,00,16,16], models[1].fit)
inputlayer.registerCallback([00,16,16,16], models[2].fit)
inputlayer.registerCallback([16,16,16,16], models[3].fit)

inputlayer.feedWebcam()





"""
for i in xrange(2):
for model in models:
model.fit(train_data)
model.save_parameters()
for model in models:
model.write_activation_summary()
model.write_activation_summary()
"""







3 changes: 1 addition & 2 deletions model/stacked_autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def assertions(self):
assert utils.noise_validator(
self.noise, allowed_noises), "Incorrect noise given"

def __init__(self, dims, activations, epoch=1000, noise=None, loss='rmse',
lr=0.001, batch_size=100, session=None):
def __init__(self, dims, activations, epoch=1000, noise=None, loss='rmse', lr=0.001, batch_size=100, session=None):
self.batch_size = batch_size
self.lr = lr
self.loss = loss
Expand Down

0 comments on commit b15ceec

Please sign in to comment.