Hvass-Labs / TensorFlow-Tutorials

TensorFlow Tutorials with YouTube Videos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ValueError: Unknown loss function:sparse_cross_entropy

chandreshiit opened this issue · comments

Hi,

While loading my saved model following your 21_machine_translation tutorial, I got the above error.
from keras.models import load_model model = load_model(data_path+'seq2seq_desc.h5')
Full error:

ValueError Traceback (most recent call last)
in
1 # load the model
2 from keras.models import load_model
----> 3 model = load_model(data_path+'seq2seq_desc.h5')
4
5

~/ckm/py3/lib/python3.5/site-packages/keras/engine/saving.py in load_model(filepath, custom_objects, compile)
417 f = h5dict(filepath, 'r')
418 try:
--> 419 model = _deserialize_model(f, custom_objects, compile)
420 finally:
421 if opened_new_file:

~/ckm/py3/lib/python3.5/site-packages/keras/engine/saving.py in _deserialize_model(f, custom_objects, compile)
310 metrics=metrics,
311 loss_weights=loss_weights,
--> 312 sample_weight_mode=sample_weight_mode)
313
314 # Set optimizer weights.

~/ckm/py3/lib/python3.5/site-packages/keras/engine/training.py in compile(self, optimizer, loss, metrics, loss_weights, sample_weight_mode, weighted_metrics, target_tensors, **kwargs)
137 loss_functions = [losses.get(l) for l in loss]
138 else:
--> 139 loss_function = losses.get(loss)
140 loss_functions = [loss_function for _ in range(len(self.outputs))]
141 self.loss_functions = loss_functions

~/ckm/py3/lib/python3.5/site-packages/keras/losses.py in get(identifier)
131 if isinstance(identifier, six.string_types):
132 identifier = str(identifier)
--> 133 return deserialize(identifier)
134 if isinstance(identifier, dict):
135 return deserialize(identifier)

~/ckm/py3/lib/python3.5/site-packages/keras/losses.py in deserialize(name, custom_objects)
112 module_objects=globals(),
113 custom_objects=custom_objects,
--> 114 printable_module_name='loss function')
115
116

~/ckm/py3/lib/python3.5/site-packages/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
163 if fn is None:
164 raise ValueError('Unknown ' + printable_module_name +
--> 165 ':' + function_name)
166 return fn
167 else:

ValueError: Unknown loss function:sparse_cross_entropy

STOP!

Please don't waste my time!

Most of the problems people are having are already described in the installation instructions.

You should first make a serious attempt to solve your problem.
If you ask a question that has already been answered elsewhere, or if you do not
give enough details about your problem, then your issue may be closed immediately.

Python 3

These tutorials were developed in Python 3.5 (and higher) and may give strange errors in Python 2.7

Missing Files

You need to download the whole repository, either using git clone or as a zip-file. See the installation instructions.

Questions about TensorFlow

General questions about TensorFlow should either be asked on StackOverflow or the official TensorFlow repository.

Modifications

Questions about modifications or how to use these tutorials on your own data-set should also be asked on StackOverflow.

Thousands of people are using these tutorials. It is impossible for me to give individual support for your project.

Suggestions for Changes

The tutorials cannot change too much because it would make the YouTube videos too different from the source-code.

Requests for New Tutorials

These tutorials were made by a single person on his own time. It took a very long time to
research and produce the tutorials. If a topic is not covered then the best thing is to make
a new tutorial by yourself. All you need is a decent microphone, a screen-grabbing tool, and a
video editor. I used the free version of DaVinci Resolve.

Other Issues?

Please carefully read the installation instructions and only open an issue if you are still having problems.

It has been over a year since I made that tutorial so I don't remember exactly how it works.

My guess would be that either the TensorFlow / Keras API has changed, in which case you can try and downgrade to the version used in the tutorial. Or you have modified the tutorial and introduced a bug in the code somewhere. Does the original tutorial work? If it works, then it is likely a bug in your modified code.

If you find the solution then please write it here, so it may help others in the future.

I have checked that Tutorial 21 works with TensorFlow version 1.12.0 and Keras version 2.1.6-tf running on Ubuntu 16 with a GTX 1070 GPU.

I don't know what is causing your problem, but everything works fine on my system.

When you file error reports, it is important that you are very specific about the system you are running, the errors you experience, and whether you have made any modifications to the code.

I just wasted an hour checking this works, because you weren't being clear. I'm not happy about that!