def tensor(dtype, ndim, name=None, fixed_shape=None): """ Create tensor variable from given information """ if is_theano(): #if fixed_shape is not None: # print 'fixed shape ignored in Theano' return T.TensorType(dtype, [False] * ndim)(name) elif is_cgt(): return cgt.tensor(dtype, ndim, name, fixed_shape) else: return tf_var_from_shape(name, fixed_shape, dtype, ndim)
def tensor_like(x): return cgt.tensor(x.dtype, x.ndim)
def inputLayer(shape_as_tuple): ndim = len(shape_as_tuple) return cgt.tensor(ndim=ndim, fixed_shape=shape_as_tuple)
infile = "/Users/joschu/Src/caffe/examples/mnist/lenet.prototxt" # infile = "/Users/joschu/Src/caffe/models/bvlc_googlenet/train_val.prototxt" with open(osp.expanduser(infile), "r") as fh: text = fh.read() net = NetParameter() text_format.Merge(text, net) name2node = {} cgt.set_precision('single') if net.input: #pylint: disable=E1101 assert len(net.input) == 1 #pylint: disable=E1101 name2node[net.input[0]] = cgt.tensor(ndim=4, dtype=cgt.floatX, fixed_shape=tuple(net.input_dim)) # XXX super inefficient for layer in net.layer: #pylint: disable=E1101 if layer.phase == TRAIN: print "loading layer %s type=%s in=%s out=%s" % ( layer.name, layer.type, layer.bottom, layer.top) output = None inputs = [name2node[name] for name in layer.bottom] if layer.type == "Data": tp = layer.transform_param crop_size = tp.crop_size chans = len(tp.mean_value) dp = layer.data_param
infile = "/Users/joschu/Src/caffe/examples/mnist/lenet.prototxt" # infile = "/Users/joschu/Src/caffe/models/bvlc_googlenet/train_val.prototxt" with open(osp.expanduser(infile),"r") as fh: text = fh.read() net = NetParameter() text_format.Merge(text, net) name2node = {} cgt.set_precision('single') if net.input: #pylint: disable=E1101 assert len(net.input) == 1 #pylint: disable=E1101 name2node[net.input[0]] = cgt.tensor(ndim=4,dtype=cgt.floatX, fixed_shape=tuple(net.input_dim)) # XXX super inefficient for layer in net.layer: #pylint: disable=E1101 if layer.phase==TRAIN: print "loading layer %s type=%s in=%s out=%s"%(layer.name, layer.type, layer.bottom, layer.top) output = None inputs = [name2node[name] for name in layer.bottom] if layer.type == "Data": tp = layer.transform_param crop_size = tp.crop_size chans = len(tp.mean_value) dp = layer.data_param batch_size = dp.batch_size