lucko515 / speech-recognition-neural-network

This is the end-to-end Speech Recognition neural network, deployed in Keras. This was my final project for Artificial Intelligence Nanodegree @Udacity.
187 stars 87 forks source link

UnicodeDecodeError: 'rawunicodeescape' codec can't decode bytes in position 54-55: truncated \uXXXX #2

Closed Sledge- closed 5 years ago

Sledge- commented 6 years ago

This is really great work first of all.

I do see a bug when I get to train_model(...) step.

I'm using Windows 10, my Keras version is 2.0.5, and Tensorflow version is 1.2.1.

The stack trace is as follows:

Epoch 1/20
100/101 [============================>.] - ETA: 0s - loss: 876.5908
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-7-8b7039598497> in <module>()
      2             pickle_path='model_0.pickle',
      3             save_model_path='model_0.h5',
----> 4             spectrogram=True) # change to False if you would like to use MFCC features

~\Deep Learning\AIND-VUI-Capstone\train_utils.py in train_model(input_to_softmax, pickle_path, save_model_path, train_json, valid_json, minibatch_size, spectrogram, mfcc_dim, optimizer, epochs, verbose, sort_by_duration, max_duration)
     74     hist = model.fit_generator(generator=audio_gen.next_train(), steps_per_epoch=steps_per_epoch,
     75         epochs=epochs, validation_data=audio_gen.next_valid(), validation_steps=validation_steps,
---> 76         callbacks=[checkpointer], verbose=verbose)
     77 
     78     # save model loss

~\AppData\Local\conda\conda\envs\aind-vui\lib\site-packages\keras\legacy\interfaces.py in wrapper(*args, **kwargs)
     86                 warnings.warn('Update your `' + object_name +
     87                               '` call to the Keras 2 API: ' + signature, stacklevel=2)
---> 88             return func(*args, **kwargs)
     89         wrapper._legacy_support_signature = inspect.getargspec(func)
     90         return wrapper

~\AppData\Local\conda\conda\envs\aind-vui\lib\site-packages\keras\engine\training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_q_size, workers, pickle_safe, initial_epoch)
   1937                             epoch_logs['val_' + l] = o
   1938 
-> 1939                 callbacks.on_epoch_end(epoch, epoch_logs)
   1940                 epoch += 1
   1941                 if callback_model.stop_training:

~\AppData\Local\conda\conda\envs\aind-vui\lib\site-packages\keras\callbacks.py in on_epoch_end(self, epoch, logs)
     75         logs = logs or {}
     76         for callback in self.callbacks:
---> 77             callback.on_epoch_end(epoch, logs)
     78 
     79     def on_batch_begin(self, batch, logs=None):

~\AppData\Local\conda\conda\envs\aind-vui\lib\site-packages\keras\callbacks.py in on_epoch_end(self, epoch, logs)
    426                     self.model.save_weights(filepath, overwrite=True)
    427                 else:
--> 428                     self.model.save(filepath, overwrite=True)
    429 
    430 

~\AppData\Local\conda\conda\envs\aind-vui\lib\site-packages\keras\engine\topology.py in save(self, filepath, overwrite, include_optimizer)
   2504         """
   2505         from ..models import save_model
-> 2506         save_model(self, filepath, overwrite, include_optimizer)
   2507 
   2508     def save_weights(self, filepath, overwrite=True):

~\AppData\Local\conda\conda\envs\aind-vui\lib\site-packages\keras\models.py in save_model(model, filepath, overwrite, include_optimizer)
    104     f.attrs['model_config'] = json.dumps({
    105         'class_name': model.__class__.__name__,
--> 106         'config': model.get_config()
    107     }, default=get_json_type).encode('utf8')
    108 

~\AppData\Local\conda\conda\envs\aind-vui\lib\site-packages\keras\engine\topology.py in get_config(self)
   2320         for layer in self.layers:  # From the earliest layers on.
   2321             layer_class_name = layer.__class__.__name__
-> 2322             layer_config = layer.get_config()
   2323             filtered_inbound_nodes = []
   2324             for original_node_index, node in enumerate(layer.inbound_nodes):

~\AppData\Local\conda\conda\envs\aind-vui\lib\site-packages\keras\layers\core.py in get_config(self)
    659     def get_config(self):
    660         if isinstance(self.function, python_types.LambdaType):
--> 661             function = func_dump(self.function)
    662             function_type = 'lambda'
    663         else:

~\AppData\Local\conda\conda\envs\aind-vui\lib\site-packages\keras\utils\generic_utils.py in func_dump(func)
    174         A tuple `(code, defaults, closure)`.
    175     """
--> 176     code = marshal.dumps(func.__code__).decode('raw_unicode_escape')
    177     defaults = func.__defaults__
    178     if func.__closure__:

UnicodeDecodeError: 'rawunicodeescape' codec can't decode bytes in position 54-55: truncated \uXXXX

It's possible that this is a bug in Keras as per this issue:
https://stackoverflow.com/questions/41847376/keras-model-to-json-error-rawunicodeescape-codec-cant-decode-bytes-in-posi https://github.com/keras-team/keras/pull/8572

I'm not sure what to try next. Anyone else seeing this issue?

lucko515 commented 6 years ago

Hey there,

I had the same issue, it is issue in Keras on Windows 10. Here is the solution:

  1. Find the file keras/utils/generic_utils.py that you are using for the project. NOTE: If you are doing this in Anaconda environment be sure to check the env folder.
  2. Copy generic_utils.py to something like OLDgeneric_utils.py to be safe
  3. Open the generic_utils.py file and change this code line: marshal.dumps(func.code).decode(‘raw_unicode_escape’) to this code line: marshal.dumps(func.code).replace(b’\’,b’/’).decode(‘raw_unicode_escape’)

I hope this solves your problem. :-)

Sledge- commented 6 years ago

Thanks for the advice. I'm going to try it. Just a few things:

My file contains this line instead: code = marshal.dumps(func.__code__).decode('raw_unicode_escape')

Also, doesn't the backslash escape the terminating quote? I would have to use this instead: code = marshal.dumps(func.__code__).replace(b'\\',b'/').decode('raw_unicode_escape')

Sledge- commented 6 years ago

I didn't realize that github used _ and \ for formatting. What you typed is correct but the way it renders in the comment makes it look wrong.

When I took that into account and changed the file, it worked. Good find!

lucko515 commented 6 years ago

Nice! I am glad that I was able to help you.