solivr / tf-crnn

TensorFlow convolutional recurrent neural network (CRNN) for text recognition
GNU General Public License v3.0
292 stars 98 forks source link

'Params' object has no attribute 'get' #29

Closed KienVu2368 closed 6 years ago

KienVu2368 commented 6 years ago

After trained model. I run python export_model.py and got error

/home/zero/tensorflow/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Traceback (most recent call last):
  File "export_model.py", line 45, in <module>
    serving_input_receiver_fn=preprocess_image_for_prediction(min_width=10))
  File "/home/zero/tensorflow/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 436, in export_savedmodel
    mode=model_fn_lib.ModeKeys.PREDICT)
  File "/home/zero/tensorflow/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 615, in _call_model_fn
    model_fn_results = self._model_fn(features=features, **kwargs)
  File "/home/zero/tf-crnn/src/model.py", line 382, in crnn_fn
    parameters = params.get('Params')
AttributeError: 'Params' object has no attribute 'get'

I run in Ubuntu 16 with cpu and tensorflow 1.3. Please let me know if anyone has solved this.

JcmeLs commented 6 years ago

you can change 'parameters = params.get('Params')' to 'parameters = params' on model.py when you export

KienVu2368 commented 6 years ago

@JcmeLs I got another error after edit model.py

Traceback (most recent call last):
  File "export_model.py", line 45, in <module>
    serving_input_receiver_fn=preprocess_image_for_prediction(min_width=10))
  File "/home/dg/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 525, in export_savedmodel
    export_dir = get_timestamped_export_dir(export_dir_base)
  File "/home/dg/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/export/export.py", line 257, in get_timestamped_export_dir
    compat.as_bytes(export_dir_base),
  File "/home/dg/anaconda3/lib/python3.6/site-packages/tensorflow/python/util/compat.py", line 65, in as_bytes
    (bytes_or_text,))
TypeError: Expected binary or unicode string, got None

Do you know how to fix it?

JcmeLs commented 6 years ago

TensorFlow version=1.3?

JcmeLs commented 6 years ago

'Params' object has no attribute 'get' ,this problem you can only change export.py, not need change model.py.
code:params_json = import_params_from_json(args.get('model_dir')) params = Params(**params_json) model_params = { 'Params': params, }

Config

est_config = tf.estimator.RunConfig()
est_config.replace(keep_checkpoint_max=10,
                   save_checkpoints_steps=params.save_interval,
                   session_config=config_sess,
                   save_checkpoints_secs=None,
                   save_summary_steps=1000)

estimator = tf.estimator.Estimator(model_fn=crnn_fn, params=model_params,
                                   model_dir=args.get('model_dir'),
                                   config=est_config,
                                   )
KienVu2368 commented 6 years ago

@JcmeLs correct me if Im wrong. I edited file export_model.py from

    # Import parameters from the json file
    params_json = import_params_from_json(args.get('model_dir'))
    params = Params(**params_json)

    # Config
    est_config = tf.estimator.RunConfig()
    est_config.replace(keep_checkpoint_max=10,
                       save_checkpoints_steps=params.save_interval,
                       session_config=config_sess,
                       save_checkpoints_secs=None,
                       save_summary_steps=1000)

    estimator = tf.estimator.Estimator(model_fn=crnn_fn, params=params,
                                       model_dir=args.get('model_dir'),
                                       config=est_config,
)

to

params_json = import_params_from_json(args.get('model_dir'))
params = Params(**params_json)
model_params = {
'Params': params,
}
# Config
est_config = tf.estimator.RunConfig()
est_config.replace(keep_checkpoint_max=10,
save_checkpoints_steps=params.save_interval,
session_config=config_sess,
save_checkpoints_secs=None,
save_summary_steps=1000)

estimator = tf.estimator.Estimator(model_fn=crnn_fn, params=model_params,
                                   model_dir=args.get('model_dir'),
                                   config=est_config,
                                   )

and keep file model.py as original

But I got new error

Traceback (most recent call last):
  File "export_model.py", line 45, in <module>
    serving_input_receiver_fn=preprocess_image_for_prediction(min_width=10))
  File "/home/dg/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 525, in export_savedmodel
    export_dir = get_timestamped_export_dir(export_dir_base)
  File "/home/dg/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/export/export.py", line 257, in get_timestamped_export_dir
    compat.as_bytes(export_dir_base),
  File "/home/dg/anaconda3/lib/python3.6/site-packages/tensorflow/python/util/compat.py", line 65, in as_bytes
    (bytes_or_text,))
TypeError: Expected binary or unicode string, got None

I think because export_dir_base is None I run in Ubuntu 16 with cpu and tensorflow 1.3.

JcmeLs commented 6 years ago

@KienVu2368 yes,just change estimator.export_savedmodel(args.get('export_dir'), serving_input_receiver_fn=preprocess_image_for_prediction(min_width=10)) to estimator.export_savedmodel(args.get('output_dir'), serving_input_receiver_fn=preprocess_image_for_prediction(min_width=10))

KienVu2368 commented 6 years ago

Thank you so much @JcmeLs :D