Skip to content

Commit

Permalink
pep8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
elggem committed Feb 14, 2017
1 parent c9593ac commit a119ebe
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 43 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ install:
- pip install numpy matplotlib colorlog pep8 pytest protobuf catkin_pkg
- pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
script:
- python setup.py develop
- python setup.py install
- pytest src/tensorflow_node/tests
- pep8 --ignore=E501 .
# Disable daemon branch for now...
#branches:
# except:
# - daemon
branches:
except:
- development
2 changes: 0 additions & 2 deletions src/tensorflow_node/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
from .nodes import AutoEncoderNode
from .nodes import StackedAutoEncoderNode
from .architectures import *

#from ..destin.msg import DestinNodeState
4 changes: 2 additions & 2 deletions src/tensorflow_node/architectures/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from tensorflow_node.nodes import *


class NetworkArchitecture(object):
__metaclass__ = abc.ABCMeta

Expand All @@ -15,10 +16,9 @@ def __init__(self):
self.nodes = []
pass


def str_to_class(self, str):
return getattr(sys.modules[__name__], str)

def create_node(self, session, node_type, node_params):
node_class = self.str_to_class(node_type)
return node_class(session, **node_params)
return node_class(session, **node_params)
35 changes: 14 additions & 21 deletions src/tensorflow_node/architectures/destin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
from tensorflow_node.nodes import *
from tensorflow_node.architectures import NetworkArchitecture


class DestinArchitecture(NetworkArchitecture):

def __init__(self, session, inputlayer, node_type, node_params, receptive_field=[14,14], stride=[7,7]):
# TODO Assertions:
def __init__(self, session, inputlayer, node_type, node_params, receptive_field=[14, 14], stride=[7, 7]):
# TODO Assertions:
# - inputlayer size and receptive field / stride fit together...
# - ...?

self.nodes = []
self.train_op = []

Expand All @@ -25,33 +26,25 @@ def destin_node(level, number_of_layers, x_pos=0.0, y_pos=0.0):
print " creating node @ level %i" % level
node = self.create_node(session, node_type, node_params)

if (level<number_of_layers):
node.register_tensor(destin_node(level+1, number_of_layers, x_pos, y_pos))
node.register_tensor(destin_node(level+1, number_of_layers, x_pos+stride[0], y_pos))
node.register_tensor(destin_node(level+1, number_of_layers, x_pos, y_pos+stride[1]))
node.register_tensor(destin_node(level+1, number_of_layers, x_pos+stride[0], y_pos+stride[1]))
if (level < number_of_layers):
node.register_tensor(destin_node(level + 1, number_of_layers, x_pos, y_pos))
node.register_tensor(destin_node(level + 1, number_of_layers, x_pos + stride[0], y_pos))
node.register_tensor(destin_node(level + 1, number_of_layers, x_pos, y_pos + stride[1]))
node.register_tensor(destin_node(level + 1, number_of_layers, x_pos + stride[0], y_pos + stride[1]))
else:
region = [int(np.round(x_pos)),int(np.round(y_pos)),receptive_field[0],receptive_field[1]]
region = [int(np.round(x_pos)), int(np.round(y_pos)), receptive_field[0], receptive_field[1]]
print " registering region @ %i %i" % (x_pos, y_pos)
node.register_tensor(inputlayer.get_tensor_for_region(region))

node.initialize_graph()

self.nodes.append(node)
self.train_op.append(node.train_op)

return node.get_output_tensor()

# calculate number of levels needed...
nr_of_layers = np.floor(np.log(np.power(inputlayer.output_size[0]/stride[0],2))/np.log(4))
nr_of_layers = np.floor(np.log(np.power(inputlayer.output_size[0] / stride[0], 2)) / np.log(4))

# create network
destin_node(0, nr_of_layers)








7 changes: 3 additions & 4 deletions src/tensorflow_node/architectures/handcoded_destin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from tensorflow_node.architectures import NetworkArchitecture


class HandcodedDestinArchitecture(NetworkArchitecture):

def __init__(self, session, inputlayer, node_type, node_params):
Expand All @@ -17,13 +18,13 @@ def __init__(self, session, inputlayer, node_type, node_params):

node_params["name"] = "bottom_b"
ae_bottom_b = self.create_node(session, node_type, node_params)

node_params["name"] = "bottom_c"
ae_bottom_c = self.create_node(session, node_type, node_params)

node_params["name"] = "bottom_d"
ae_bottom_d = self.create_node(session, node_type, node_params)

node_params["name"] = "top"
ae_top = self.create_node(session, node_type, node_params)

Expand All @@ -41,5 +42,3 @@ def __init__(self, session, inputlayer, node_type, node_params):

self.nodes = [ae_bottom_a, ae_bottom_b, ae_bottom_c, ae_bottom_d, ae_top]
self.train_op = [ae_bottom_a.train_op, ae_bottom_b.train_op, ae_bottom_c.train_op, ae_bottom_d.train_op, ae_top.train_op]


2 changes: 1 addition & 1 deletion src/tensorflow_node/input/opencv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, batch_size=1, output_size=[28, 28], input="", number_of_frame
self.repeat = repeat

def feed_to(self, feed_callback):

# TODO: there should be clearer distinction here, get these params via daemon.
frames = rospy.get_param("tensorflow_node/inputlayer/params/number_of_frames")
repeat = rospy.get_param("tensorflow_node/inputlayer/params/repeat")
Expand Down
8 changes: 4 additions & 4 deletions src/tensorflow_node/input/ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from skimage import transform

from tensorflow_node.input import InputLayer

from sensor_msgs.msg import Image


class ROSInputLayer(InputLayer):
"""
Contains ROS to feed in images and video feeds to TF.
Expand All @@ -22,8 +22,8 @@ def callback(ros_data):
np_arr = np.fromstring(ros_data.data, np.uint8).reshape(ros_data.width, ros_data.height, 3)

# Grayscale conversion
channels = np_arr.swapaxes(0,2)
gray = (channels[0] + channels[1] + channels[2]) / 3 # could to different weights per channel here
channels = np_arr.swapaxes(0, 2)
gray = (channels[0] + channels[1] + channels[2]) / 3 # could to different weights per channel here

# Resize to normalized input layer size
resized = transform.resize(gray, [self.output_size[0], self.output_size[1]]).reshape([self.output_size[0], self.output_size[1], 1])
Expand All @@ -43,7 +43,7 @@ def callback(ros_data):

rospy.loginfo("ROSInputLayer: Evaluated batch")

## ROS subscribe...
# ROS subscribe...
rospy.logwarn("Subscribing to topic " + self.input)
topic_name = self.input
rospy.Subscriber(topic_name, Image, callback)
6 changes: 3 additions & 3 deletions src/tensorflow_node/nodes/autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def __init__(self,
lr=0.007):

self.name = name
if self.name=="ae":

if self.name == "ae":
self.name = 'ae_%08x' % random.getrandbits(32)

self.session = session

# this list is populated with register tensor function
Expand Down
4 changes: 2 additions & 2 deletions src/tensorflow_node/utils/summary_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import rospy

# Singleton

class SummaryWriter(object):
_instance = None

Expand All @@ -26,7 +26,7 @@ def __init__(self):
self.writer = tf.train.SummaryWriter(self.directory)

def get_output_folder(self, path):
#output_path = pjoin(os.getcwd(), 'output', path)
# output_path = pjoin(os.getcwd(), 'output', path)
output_path = rospy.get_param("tensorflow_node/publishing/summary_folder")
if not os.path.exists(output_path):
os.makedirs(output_path)
Expand Down

0 comments on commit a119ebe

Please sign in to comment.