Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
output_ply/
tmp/
5 changes: 1 addition & 4 deletions ResNet/ThreeDMM_expr.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import sys
#sys.path.append('../kaffe')
sys.path.append('/home/usc/Desktop/Research/FG18/ExpNet_Code_Release/kaffe/tensorflow')
from network_expr import Network_Expr
from kaffe.tensorflow import Network_Expr


class ResNet_101(Network_Expr):
Expand Down
7 changes: 1 addition & 6 deletions ResNet/ThreeDMM_shape.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import sys
#sys.path.append('../kaffe')
sys.path.append('/home/usc/Desktop/Research/FG18/ExpNet_Code_Release/kaffe/tensorflow')
from network_shape import Network_Shape


from kaffe.tensorflow import Network_Shape

class ResNet_101(Network_Shape):
def setup(self):
Expand Down
1 change: 1 addition & 0 deletions kaffe/caffe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .resolver import get_caffe_resolver, has_pycaffe
5,479 changes: 5,479 additions & 0 deletions kaffe/caffe/caffepb.py

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions kaffe/caffe/resolver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import sys

SHARED_CAFFE_RESOLVER = None

class CaffeResolver(object):
def __init__(self):
self.import_caffe()

def import_caffe(self):
self.caffe = None
try:
# Try to import PyCaffe first
import caffe
self.caffe = caffe
except ImportError:
# Fall back to the protobuf implementation
from . import caffepb
self.caffepb = caffepb
show_fallback_warning()
if self.caffe:
# Use the protobuf code from the imported distribution.
# This way, Caffe variants with custom layers will work.
self.caffepb = self.caffe.proto.caffe_pb2
self.NetParameter = self.caffepb.NetParameter

def has_pycaffe(self):
return self.caffe is not None

def get_caffe_resolver():
global SHARED_CAFFE_RESOLVER
if SHARED_CAFFE_RESOLVER is None:
SHARED_CAFFE_RESOLVER = CaffeResolver()
return SHARED_CAFFE_RESOLVER

def has_pycaffe():
return get_caffe_resolver().has_pycaffe()

def show_fallback_warning():
msg = '''
------------------------------------------------------------
WARNING: PyCaffe not found!
Falling back to a pure protocol buffer implementation.
* Conversions will be drastically slower.
* This backend is UNTESTED!
------------------------------------------------------------

'''
sys.stderr.write(msg)
3 changes: 2 additions & 1 deletion kaffe/tensorflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .transformer import TensorFlowTransformer
from .network import Network
from .network_expr import Network_Expr
from .network_shape import Network_Shape
4 changes: 2 additions & 2 deletions kaffe/tensorflow/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ..transformers import (DataInjector, DataReshaper, NodeRenamer, ReLUFuser,
BatchNormScaleBiasFuser, BatchNormPreprocessor, ParameterNamer)

from . import network
from . import network_expr


def get_padding_type(kernel_params, input_shape, output_shape):
Expand Down Expand Up @@ -82,7 +82,7 @@ def get_kernel_params(self, node):
input_shape = node.get_only_parent().output_shape
padding = get_padding_type(kernel_params, input_shape, node.output_shape)
# Only emit the padding if it's not the default value.
padding = {'padding': padding} if padding != network.DEFAULT_PADDING else {}
padding = {'padding': padding} if padding != network_expr.DEFAULT_PADDING else {}
return (kernel_params, padding)

def map_convolution(self, node):
Expand Down