Skip to content

Commit

Permalink
SINGA-295 - Add an example of image classification using GoogleNet
Browse files Browse the repository at this point in the history
fixed a bug in tensor.py to_numpy()
  • Loading branch information
nudles committed Jan 23, 2017
1 parent 114592b commit 8c990f7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/imagenet/googlenet/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: GoogleNet on ImageNet
SINGA version: 1.0.1
SINGA commit:
SINGA commit: 4e47499e5c3ad3a8081abb0a9a2fca0f6d317241
parameter_url: https://s3-ap-southeast-1.amazonaws.com/dlfile/bvlc_googlenet.tar.gz
parameter_sha1: 0a88e8948b1abca3badfd8d090d6be03f8d7655d
license: unrestricted https://github.com/BVLC/caffe/tree/master/models/bvlc_googlenet
Expand Down
10 changes: 2 additions & 8 deletions examples/imagenet/googlenet/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,19 @@ def setup(self, input_sample_shape):

def forward(self, flag, x):
'''pad zeros'''
dev = x.device
x.to_host()
tmp = tensor.to_numpy(x)
shape = add_to_tuple(x.shape)
ret = np.zeros(shape)
ret[:,:,:-1, :-1] = tmp
y = tensor.from_numpy(ret)
x.to_device(dev)
y.to_device(dev)
y.to_device(x.device)
return y

def backward(self, falg, dy):
'''remove paddings'''
dev = dy.device
dy.to_host()
tmp = tensor.to_numpy(dy)
dx = tensor.from_numpy(tmp[:,:,:-1,:-1])
dx.to_device(dev)
dy.to_device(dev)
dx.to_device(dy.device)
return dx, []

# b_specs = {'init': 'constant', 'value': 0, 'lr_mult': 2, 'decay_mult': 0}
Expand Down
4 changes: 2 additions & 2 deletions python/singa/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,9 @@ def to_numpy(t):
'''
th = to_host(t)
if th.dtype == core_pb2.kFloat32:
np_array = ret.singa_tensor.GetFloatValue(int(th.size()))
np_array = th.singa_tensor.GetFloatValue(int(th.size()))
elif th.dtype == core_pb2.kInt:
np_array = ret.singa_tensor.GetIntValue(int(th.size()))
np_array = th.singa_tensor.GetIntValue(int(th.size()))
else:
print 'Not implemented yet for ', th.dtype
return np_array.reshape(th.shape)
Expand Down

0 comments on commit 8c990f7

Please sign in to comment.