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

Testing Trained Weights #17

Open
ElliotEckholm opened this issue May 25, 2020 · 11 comments
Open

Testing Trained Weights #17

ElliotEckholm opened this issue May 25, 2020 · 11 comments

Comments

@ElliotEckholm
Copy link

Currently trying to test the trained weights that were already provided, but getting an error.

I downloaded the taco_10_3.zip, placed the split data and .h5 in the mentioned directories.

Then ran this command:
python3 detector.py test --dataset=../data --model=./models/logs/mask_rcnn_taco_0100.h5 --round 3 --class_map=./taco_config/map_3.csv

This is the error:

Traceback (most recent call last): File "detector.py", line 283, in <module> model.load_weights(model_path, by_name=True) File "/Users/ellioteckholm/Documents/AI/Pre_trained_TACO/detector/model.py", line 2088, in load_weights topology.load_weights_from_hdf5_group_by_name(f, layers) File "/usr/local/lib/python3.7/site-packages/keras/engine/topology.py", line 3479, in load_weights_from_hdf5_group_by_name K.batch_set_value(weight_value_tuples) File "/usr/local/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 2372, in batch_set_value assign_op = x.assign(assign_placeholder) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/ops/variables.py", line 2067, in assign self._variable, value, use_locking=use_locking, name=name) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/ops/state_ops.py", line 227, in assign validate_shape=validate_shape) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_state_ops.py", line 66, in assign use_locking=use_locking, name=name) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/framework/op_def_library.py", line 794, in _apply_op_helper op_def=op_def) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func return func(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3357, in create_op attrs, op_def, compute_device) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3426, in _create_op_internal op_def=op_def) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1770, in __init__ control_input_ops) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1610, in _create_c_op raise ValueError(str(e)) ValueError: Dimension 1 in both shapes must be equal, but are 16 and 44. Shapes are [1024,16] and [1024,44]. for 'Assign_376' (op: 'Assign') with input shapes: [1024,16], [1024,44].

@alexweininger
Copy link

Getting the same error. After some research, it might be because the weights were trained using an older version of Keras or TensorFlow. Currently trying to generate new weights to try to solve this.

Any help is greatly appreciated.

@pedropro
Copy link
Owner

What version are you using?
I trained the weights using:

  • tensorflow 1.9.0
  • keras 2.16

@alexweininger
Copy link

I actually was able to get it working when I manually installed Python 3.5, Keras 2.0.8, and Tensorflow 1.3.0.

@emjay73
Copy link

emjay73 commented Oct 27, 2021

I tried "Python 3.5, Keras 2.0.8, and Tensorflow 1.3.0" setting, but failed, yielding "tensorflow has no attribute math".

@Taichipeace
Copy link

Currently trying to test the trained weights that were already provided, but getting an error.

I downloaded the taco_10_3.zip, placed the split data and .h5 in the mentioned directories.

Then ran this command: python3 detector.py test --dataset=../data --model=./models/logs/mask_rcnn_taco_0100.h5 --round 3 --class_map=./taco_config/map_3.csv

This is the error:

Traceback (most recent call last): File "detector.py", line 283, in <module> model.load_weights(model_path, by_name=True) File "/Users/ellioteckholm/Documents/AI/Pre_trained_TACO/detector/model.py", line 2088, in load_weights topology.load_weights_from_hdf5_group_by_name(f, layers) File "/usr/local/lib/python3.7/site-packages/keras/engine/topology.py", line 3479, in load_weights_from_hdf5_group_by_name K.batch_set_value(weight_value_tuples) File "/usr/local/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 2372, in batch_set_value assign_op = x.assign(assign_placeholder) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/ops/variables.py", line 2067, in assign self._variable, value, use_locking=use_locking, name=name) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/ops/state_ops.py", line 227, in assign validate_shape=validate_shape) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_state_ops.py", line 66, in assign use_locking=use_locking, name=name) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/framework/op_def_library.py", line 794, in _apply_op_helper op_def=op_def) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func return func(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3357, in create_op attrs, op_def, compute_device) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3426, in _create_op_internal op_def=op_def) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1770, in __init__ control_input_ops) File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 1610, in _create_c_op raise ValueError(str(e)) ValueError: Dimension 1 in both shapes must be equal, but are 16 and 44. Shapes are [1024,16] and [1024,44]. for 'Assign_376' (op: 'Assign') with input shapes: [1024,16], [1024,44].

Firstly, I think you should use --class_map=./taco_config/map_10.csv instead of map_3.csv
Secondly, based on detector.py, I think we should copy the .h5 file to the models/ dir, but not models/logs/

Anyway, just as you did, I downloaded the taco_10_3.zip, placed the split data and .h5 in the mentioned directories.
And I installed TensorFlow1.9.0 and Keras 2.1.6, but when running:
python detector.py test --dataset=../data --model=./models/mask_rcnn_taco_0100.h5 --round 3 --class_map=./taco_config/map_10.csv
I got this error message:
`Traceback (most recent call last):
File "D:\MVproject\ceshi\01GarbageTACO\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\MVproject\ceshi\01GarbageTACO\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 35, in
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\MVproject\ceshi\01GarbageTACO\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 30, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Python37\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: can not find module。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "detector.py", line 48, in
from dataset import Taco
File "D:\MVproject\ceshi\01GarbageTACO\TACO-master\detector\dataset.py", line 11, in
import utils
File "D:\MVproject\ceshi\01GarbageTACO\TACO-master\detector\utils.py", line 19, in
import tensorflow as tf
File "D:\MVproject\ceshi\01GarbageTACO\venv\lib\site-packages\tensorflow_init_.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "D:\MVproject\ceshi\01GarbageTACO\venv\lib\site-packages\tensorflow\python_init_.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "D:\MVproject\ceshi\01GarbageTACO\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "D:\MVproject\ceshi\01GarbageTACO\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\MVproject\ceshi\01GarbageTACO\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 35, in
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\MVproject\ceshi\01GarbageTACO\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 30, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Python37\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: can not find module。

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
`

I'm really stacked here, anyone could help please?
Thanks

@farcaz
Copy link

farcaz commented Nov 26, 2021

I tried "Python 3.5, Keras 2.0.8, and Tensorflow 1.3.0" setting, but failed, yielding "tensorflow has no attribute math".

use 'tf.divide' instead of 'tf.math.divide'
source: https://stackoverflow.com/questions/68673846/attributeerror-module-tensorflow-has-no-attribute-div

@GDICK14
Copy link

GDICK14 commented Feb 25, 2022

I tried "Python 3.5, Keras 2.0.8, and Tensorflow 1.3.0" setting, but failed, yielding "tensorflow has no attribute math".

use 'tf.divide' instead of 'tf.math.divide' source: https://stackoverflow.com/questions/68673846/attributeerror-module-tensorflow-has-no-attribute-div

Worked for me.
FYI, I then got an assertion error in model.py, "assert model_name = in dir_names". For me this was due to the .DS_File messing up next(os.walk(self.model_dir). Created a new assertion taking files from os.walk

@rishabh0282
Copy link

I tried "Python 3.5, Keras 2.0.8, and Tensorflow 1.3.0" setting, but failed, yielding "tensorflow has no attribute math".

use 'tf.divide' instead of 'tf.math.divide' source: https://stackoverflow.com/questions/68673846/attributeerror-module-tensorflow-has-no-attribute-div

Worked for me. FYI, I then got an assertion error in model.py, "assert model_name = in dir_names". For me this was due to the .DS_File messing up next(os.walk(self.model_dir). Created a new assertion taking files from os.walk

I am getting the same error not able to make it work. Can you please help me with this error and what changes you made?

@PoltoraninKE
Copy link

I tried "Python 3.5, Keras 2.0.8, and Tensorflow 1.3.0" setting, but failed, yielding "tensorflow has no attribute math".

use 'tf.divide' instead of 'tf.math.divide' source: https://stackoverflow.com/questions/68673846/attributeerror-module-tensorflow-has-no-attribute-div

Worked for me. FYI, I then got an assertion error in model.py, "assert model_name = in dir_names". For me this was due to the .DS_File messing up next(os.walk(self.model_dir). Created a new assertion taking files from os.walk

I am getting the same error not able to make it work. Can you please help me with this error and what changes you made?

Just download these versions:
Keras 2.0.8
Tensorflow 1.15.0
But after download I changed file in this list because it gave me some errors with decode('utf-8') so I deleted it.
Try it out

@BookGin
Copy link

BookGin commented Sep 28, 2022

The following environment works for me:

  • Ubuntu 20.04
  • Python 3.7.13
  • tensorflow 1.15.0
  • Keras 2.0.8

And manually patch keras encoding/decoding issue:

--- /home/user/anaconda3/envs/taco37/lib/python3.7/site-packages/keras/engine/topology.py  2022-09-20 13:33:37 +0000
+++ /home/user/anaconda3/envs/taco37/lib/python3.7/site-packages/keras/engine/topology.py  2022-09-20 13:33:37 +0000
@@ -3111,11 +3111,11 @@
             and weights file.
     """
     if 'keras_version' in f.attrs:
-        original_keras_version = f.attrs['keras_version']#.decode('utf8')
+        original_keras_version = f.attrs['keras_version'].decode('utf8')
     else:
         original_keras_version = '1'
     if 'backend' in f.attrs:
-        original_backend = f.attrs['backend']#.decode('utf8')
+        original_backend = f.attrs['backend'].decode('utf8')
     else:
         original_backend = None

Patch the detector so it won't use checkpoints:

index f96510e..7bcfadc 100644
--- a/detector/detector.py
+++ b/detector/detector.py
@@ -286,7 +286,10 @@ if __name__ == '__main__':
         # Start from ImageNet trained weights
         model_path = model.get_imagenet_weights()
     else:
-        _, model_path = model.get_last_checkpoint(args.model)
+        #_, model_path = model.get_last_checkpoint(args.model)
+        model_path = str(__import__("pathlib").Path(args.model).absolute())
+
+

Finally, set environment variable so protobuf can work with pure Python implementation:

export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python

@rgaufman
Copy link

Does anyone have a fork that works on modern-ish versions?

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