forked from elggem/tensorflow_node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
105 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,5 +89,4 @@ ENV/ | |
.ropeproject | ||
|
||
# tensorflow data | ||
data/* | ||
output/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mnist/ |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .inputlayer import InputLayer | ||
from .opencv import OpenCVInputLayer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
""" | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters