New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model zoo (fix #3) #110

Merged
merged 20 commits into from Jul 2, 2015

Conversation

Projects
None yet
5 participants
@beam2d
Member

beam2d commented Jun 30, 2015

This PR fixes #3 by adding functions.caffe.CaffeFunction, which loads a pretrained Caffe model and emulates its subnetwork. The usage is written in the reference documentation, though I also show it here. This is an example of loading BVLC reference CaffeNet and computes fc8 blob from data blob.

# Load the model
func = CaffeFunction('path/to/bvlc_reference_caffenet.caffemodel')

# Minibatch of size 10
x_data = numpy.ndarray((10, 3, 227, 227), dtype=numpy.float32)
...  # (Fill the minibatch here)

# Forward the pretrained net
x = Variable(x_data)
y, = func(inputs={'data': x}, outputs=['fc8'])

The inputs dict describes how to initialize the blobs by variables. The outputs list indicates which blobs to be output as variables. Also user can extracts parameterized layers from CaffeFunction.fs, which is a FunctionSet object containing Linear or Convolution2D objects.

'chainer.optimizers',
'chainer.requirements',
'chainer.utils'],
package_data={'chainer.requirements': ['cuda-requirements.txt']},
install_requires=['numpy',
'protobuf',

This comment has been minimized.

@unnonouno

unnonouno Jul 1, 2015

Member

Can we install protobuf in py3 environment?

@unnonouno

unnonouno Jul 1, 2015

Member

Can we install protobuf in py3 environment?

This comment has been minimized.

@beam2d

beam2d Jul 1, 2015

Member

We can install it. CI passed it, too.

@beam2d

beam2d Jul 1, 2015

Member

We can install it. CI passed it, too.

This comment has been minimized.

@unnonouno

unnonouno Jul 1, 2015

Member

OK, no problem.

@unnonouno

unnonouno Jul 1, 2015

Member

OK, no problem.

This comment has been minimized.

@unnonouno

unnonouno Jul 2, 2015

Member

Which version of protobuf is required?

@unnonouno

unnonouno Jul 2, 2015

Member

Which version of protobuf is required?

@unnonouno

This comment has been minimized.

Show comment
Hide comment
@unnonouno

unnonouno Jul 1, 2015

Member

Do you have a unit test for this function?

Member

unnonouno commented Jul 1, 2015

Do you have a unit test for this function?

@beam2d

This comment has been minimized.

Show comment
Hide comment
@beam2d

beam2d Jul 1, 2015

Member

I'm thinking about the test, though I have no good plan, yet.

Member

beam2d commented Jul 1, 2015

I'm thinking about the test, though I have no good plan, yet.

@beam2d

This comment has been minimized.

Show comment
Hide comment
@beam2d

beam2d Jul 1, 2015

Member

I'll write an example of loading and using a Caffe reference model.

Member

beam2d commented Jul 1, 2015

I'll write an example of loading and using a Caffe reference model.

@unnonouno unnonouno self-assigned this Jul 1, 2015

beam2d added some commits Jul 1, 2015

@beam2d

This comment has been minimized.

Show comment
Hide comment
@beam2d

beam2d Jul 1, 2015

Member

I added an example. However, it outputs too low accuracy. I will try to resolve this issue.

Member

beam2d commented Jul 1, 2015

I added an example. However, it outputs too low accuracy. I will try to resolve this issue.

@unnonouno

This comment has been minimized.

Show comment
Hide comment

This comment has been minimized.

Show comment
Hide comment
@unnonouno

unnonouno Jul 1, 2015

Member

And, set required

Member

unnonouno replied Jul 1, 2015

And, set required

This comment has been minimized.

Show comment
Hide comment
@beam2d

beam2d Jul 2, 2015

Member

I'll add choices. The positional argument is mandatory by default, so I think we don't need required flag.

Member

beam2d replied Jul 2, 2015

I'll add choices. The positional argument is mandatory by default, so I think we don't need required flag.

This comment has been minimized.

Show comment
Hide comment
@unnonouno
Member

unnonouno replied Jul 2, 2015

ok

@unnonouno

This comment has been minimized.

Show comment
Hide comment

This comment has been minimized.

Show comment
Hide comment
@beam2d

beam2d Jul 2, 2015

Member

We do not have to open the flag in this script (it is done by CaffeFunction). Do we still have to use FileType?

Member

beam2d replied Jul 2, 2015

We do not have to open the flag in this script (it is done by CaffeFunction). Do we still have to use FileType?

This comment has been minimized.

Show comment
Hide comment
@unnonouno

unnonouno Jul 2, 2015

Member

ok, no problem.

Member

unnonouno replied Jul 2, 2015

ok, no problem.

@unnonouno

This comment has been minimized.

Show comment
Hide comment
@unnonouno

unnonouno Jul 1, 2015

Member

Do we need to check that batchsize > 0?

Member

unnonouno commented on examples/modelzoo/evaluate_caffe_net.py in bfb78b9 Jul 1, 2015

Do we need to check that batchsize > 0?

This comment has been minimized.

Show comment
Hide comment
@beam2d

beam2d Jul 2, 2015

Member

OK, I'll add a check.

Member

beam2d replied Jul 2, 2015

OK, I'll add a check.

@unnonouno

This comment has been minimized.

Show comment
Hide comment
@unnonouno

unnonouno Jul 1, 2015

Member

Does it need? I feel it's a little complicated. Is it too slow without multi-threads?

Member

unnonouno commented on examples/modelzoo/evaluate_caffe_net.py in bfb78b9 Jul 1, 2015

Does it need? I feel it's a little complicated. Is it too slow without multi-threads?

This comment has been minimized.

Show comment
Hide comment
@beam2d

beam2d Jul 2, 2015

Member

I'll measure the time with and without threading/multiprocessing.

Member

beam2d replied Jul 2, 2015

I'll measure the time with and without threading/multiprocessing.

This comment has been minimized.

Show comment
Hide comment
@beam2d

beam2d Jul 2, 2015

Member

I measured the time, and both implementations have no difference, so I'll make the code simpler by removing the threading/multiprocessing.

Member

beam2d replied Jul 2, 2015

I measured the time, and both implementations have no difference, so I'll make the code simpler by removing the threading/multiprocessing.

This comment has been minimized.

Show comment
Hide comment
@unnonouno

unnonouno Jul 2, 2015

Member

👍

Member

unnonouno replied Jul 2, 2015

👍

@beam2d

This comment has been minimized.

Show comment
Hide comment
@beam2d

beam2d Jul 2, 2015

Member

I updated the example code.

Member

beam2d commented Jul 2, 2015

I updated the example code.

@beam2d

This comment has been minimized.

Show comment
Hide comment
@beam2d

beam2d Jul 2, 2015

Member

I updated the code. It achieves the same accuracy as the original Caffe implementation. (Actually I've fixed testing mode and RGB order)

Member

beam2d commented Jul 2, 2015

I updated the code. It achieves the same accuracy as the original Caffe implementation. (Actually I've fixed testing mode and RGB order)

@delta2323 delta2323 modified the milestone: v1.1.0 Jul 2, 2015

@okuta okuta added the feature label Jul 2, 2015

@unnonouno

This comment has been minimized.

Show comment
Hide comment
@unnonouno

unnonouno Jul 2, 2015

Member

Please chmod +x download_model.py

Member

unnonouno commented Jul 2, 2015

Please chmod +x download_model.py

.. note::
This function only supports Python 2.7, since the compiled module for

This comment has been minimized.

@unnonouno

unnonouno Jul 2, 2015

Member

What happens on py3?

@unnonouno

unnonouno Jul 2, 2015

Member

What happens on py3?

This comment has been minimized.

@beam2d

beam2d Jul 2, 2015

Member

I changed the code to raise an exception in Python 3. I also wrote this behavior in the docstring.

@beam2d

beam2d Jul 2, 2015

Member

I changed the code to raise an exception in Python 3. I also wrote this behavior in the docstring.

"""
self.train = train
variables = dict(inputs)

This comment has been minimized.

@unnonouno

unnonouno Jul 2, 2015

Member

Why is this dict required?

@unnonouno

unnonouno Jul 2, 2015

Member

Why is this dict required?

This comment has been minimized.

@beam2d

beam2d Jul 2, 2015

Member

Because it alters the dict object, I explicitly copy the dictionary here.

@beam2d

beam2d Jul 2, 2015

Member

Because it alters the dict object, I explicitly copy the dictionary here.

@beam2d

This comment has been minimized.

Show comment
Hide comment
@beam2d

beam2d Jul 2, 2015

Member

I added a warning routine on unknown layer types.

Member

beam2d commented Jul 2, 2015

I added a warning routine on unknown layer types.

@unnonouno

This comment has been minimized.

Show comment
Hide comment
@unnonouno
Member

unnonouno commented Jul 2, 2015

LGTM

unnonouno added a commit that referenced this pull request Jul 2, 2015

@unnonouno unnonouno merged commit e2ee9d6 into master Jul 2, 2015

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@itortoise

This comment has been minimized.

Show comment
Hide comment
@itortoise

itortoise Jul 6, 2015

I load my caffemodel and then Traceback ZeroDivisionError as:

File "", line 1, in
File "chainer/functions/caffe/caffe_function.py", line 119, in init
meth(self, layer)
File "chainer/functions/caffe/caffe_function.py", line 228, in _setup_convolution
nobias=not param.bias_term)
File "chainer/functions/convolution_2d.py", line 92, in init
0, wscale * math.sqrt(1. / (self.kh * self.kw * in_channels)),
ZeroDivisionError: float division by zero

itortoise commented Jul 6, 2015

I load my caffemodel and then Traceback ZeroDivisionError as:

File "", line 1, in
File "chainer/functions/caffe/caffe_function.py", line 119, in init
meth(self, layer)
File "chainer/functions/caffe/caffe_function.py", line 228, in _setup_convolution
nobias=not param.bias_term)
File "chainer/functions/convolution_2d.py", line 92, in init
0, wscale * math.sqrt(1. / (self.kh * self.kw * in_channels)),
ZeroDivisionError: float division by zero

@beam2d

This comment has been minimized.

Show comment
Hide comment
@beam2d

beam2d Jul 6, 2015

Member

@itortoise Thank you for reporting an error. Would you open another issue for this?

Member

beam2d commented Jul 6, 2015

@itortoise Thank you for reporting an error. Would you open another issue for this?

@delta2323 delta2323 deleted the model-zoo branch Jul 6, 2015

@beam2d

This comment has been minimized.

Show comment
Hide comment
@beam2d

beam2d Jul 7, 2015

Member

@itortoise #148 may fix your problem.

Member

beam2d commented Jul 7, 2015

@itortoise #148 may fix your problem.

niboshi pushed a commit to niboshi/chainer that referenced this pull request Jun 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment