Arsey/keras-transfer-learning-for-oxford102

server.py ValueError

noriando opened this issue · 0 comments

It looks like predict.py is working.
-------------------------- pythin predict.ty --path "" --model=resnet50
Creating model
Found 1 files
Batch 0
Warming up the model
Warming up took 31.234445 s
Prediction on batch 0 took: 0.306215
| should be 48 (50) -> predicted as 48.0 (50)

however server.py faced following error ...
$python server.py --model=resnet50
Using Theano backend.
WARNING (theano.sandbox.cuda): The cuda backend is deprecated and will be removed in the next release (v0.10). Please switch to the gpuarray backend. You can get more information about how to switch at this URL:
https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29

Using gpu device 0: Tesla K80 (CNMeM is disabled, cuDNN not available)
Creating model
(Subtensor{int64}.0, Elemwise{add,no_inplace}.0, Elemwise{add,no_inplace}.0, Subtensor{int64}.0)
Traceback (most recent call last):
File "server.py", line 21, in
model = model_module.load()
File "/home/norihisa_ando/oxford/keras-transfer-learning-for-oxford102/models/base_model.py", line 56, in load
self._create()
File "/home/norihisa_ando/oxford/keras-transfer-learning-for-oxford102/models/resnet50.py", line 24, in _create
x = Flatten()(x)
File "/home/norihisa_ando/.pyenv/versions/2.7.3/lib/python2.7/site-packages/keras/engine/topology.py", line 569, in call
self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
File "/home/norihisa_ando/.pyenv/versions/2.7.3/lib/python2.7/site-packages/keras/engine/topology.py", line 632, in add_inbound_node
Node.create_node(self, inbound_layers, node_indices, tensor_indices)
File "/home/norihisa_ando/.pyenv/versions/2.7.3/lib/python2.7/site-packages/keras/engine/topology.py", line 168, in create_node
output_shapes = to_list(outbound_layer.get_output_shape_for(input_shapes[0]))
File "/home/norihisa_ando/.pyenv/versions/2.7.3/lib/python2.7/site-packages/keras/layers/core.py", line 436, in get_output_shape_for
'(got ' + str(input_shape[1:]) + '. '
ValueError: The shape of the input to "Flatten" is not fully defined (got (0, 1, 2048). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.

image_dim_ordering is "th"
predict.py:keras.backend.set_image_dim_ordering('th')
train.py:keras.backend.set_image_dim_ordering('th')

SOLVED.

I just add in server.py ..... it is now woring ... ( I realized this solution when I am writing issue ... thanks)
os.environ["THEANO_FLAGS"] = "lib.cnmem=2"
keras.backend.set_image_dim_ordering('th')