Skip to content
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

Getiing ValueError: Shape must be rank 1 but is rank 0 when running rec_feat.py #11

Open
adityaguptai opened this issue Oct 6, 2018 · 6 comments

Comments

@adityaguptai
Copy link

ValueError: Shape must be rank 1 but is rank 0 for 'bn1/cond/Reshape_4' (op: 'Reshape') with input shapes: [1,64,1,1], [].

Full Stack Trace

Traceback (most recent call last):
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1567, in _create_c_op
c_op = c_api.TF_FinishOperation(op_desc)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape must be rank 1 but is rank 0 for 'bn1/cond/Reshape_4' (op: 'Reshape') with input shapes: [1,64,1,1], [].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "rec-feat.py", line 13, in
FRmodel = load_model('face-rec_Google.h5')
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/keras/engine/saving.py", line 419, in load_model
model = _deserialize_model(f, custom_objects, compile)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/keras/engine/saving.py", line 225, in _deserialize_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/keras/engine/saving.py", line 458, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/keras/layers/init.py", line 55, in deserialize
printable_module_name='layer')
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 145, in deserialize_keras_object
list(custom_objects.items())))
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/keras/engine/network.py", line 1032, in from_config
process_node(layer, node_data)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/keras/engine/network.py", line 991, in process_node
layer(unpack_singleton(input_tensors), **kwargs)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/keras/engine/base_layer.py", line 457, in call
output = self.call(inputs, **kwargs)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/keras/layers/normalization.py", line 206, in call
training=training)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 3123, in in_train_phase
x = switch(training, x, alt)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 3058, in switch
else_expression_fn)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 432, in new_func
return func(*args, **kwargs)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2072, in cond
orig_res_f, res_f = context_f.BuildCondBranch(false_fn)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1913, in BuildCondBranch
original_result = fn()
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/keras/layers/normalization.py", line 167, in normalize_inference
epsilon=self.epsilon)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 1908, in batch_normalization
mean = tf.reshape(mean, (-1))
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 6113, in reshape
"Reshape", tensor=tensor, shape=shape, name=name)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
op_def=op_def)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1734, in init
control_input_ops)
File "/home/cyanamous/anaconda3/envs/py36/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1570, in _create_c_op
raise ValueError(str(e))
ValueError: Shape must be rank 1 but is rank 0 for 'bn1/cond/Reshape_4' (op: 'Reshape') with input shapes: [1,64,1,1], [].

@insigh
Copy link

insigh commented Nov 15, 2018

hello, have you solved the problem? I have the same one with you, looking forward to your solution.

@ljcyu
Copy link

ljcyu commented Dec 26, 2018

I also meet the same problem, it is useful to try other lower version Keras .

@xaviOwO
Copy link

xaviOwO commented Jan 27, 2019

Hello the problem is given by the tensorflow version and I downloaded the V: 1.12 and it was solved.

If you have problems besides that in rec-face.py and add:
def triplet_loss (y_true, y_pred):
     from keras import backend as K
     return K.max (K.abs (y_pred - y_true), axis = -1)

And add to load_model this:

FRmodel = load_model ('face-rec_Google.h5', custom_objects = {'triplet_loss': triplet_loss})

Greetings, sorry for the translation use google translator, I speak Spanish.

@sergree
Copy link

sergree commented Mar 5, 2019

Fixed in last Keras
keras-team/keras#10648

@gdut3118007086
Copy link

pip install keras==2.1.6
or
use anaconda to get keras==2.1.6
thanks

@hayatkhan8660-maker
Copy link

hayatkhan8660-maker commented Jan 29, 2020

i solve the same problem by downgrading the keras version from 2.2.4 to 2.1.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants