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

TypeError: Object of type ndarray is not JSON serializable #14

Open
NekroniX588 opened this issue Nov 27, 2024 · 0 comments
Open

TypeError: Object of type ndarray is not JSON serializable #14

NekroniX588 opened this issue Nov 27, 2024 · 0 comments

Comments

@NekroniX588
Copy link

NekroniX588 commented Nov 27, 2024

I try to use GigaAM-rnnt according this example https://colab.research.google.com/github/salute-developers/GigaAM/blob/main/examples/notebooks/GigaAM_RNNT_Model_Usage_Example.ipynb#scrollTo=nlrRmRPvKxYq

But i have error in this part

# Transcribing segments
BATCH_SIZE = 10
transcriptions = model.transcribe(segments, batch_size=BATCH_SIZE)[0]

Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[18], line 2
      1 BATCH_SIZE = 10
----> 2 transcriptions = model.transcribe(segments, batch_size=BATCH_SIZE)[0]

File /opt/conda/envs/gigaam/lib/python3.10/site-packages/torch/utils/_contextlib.py:116, in context_decorator.<locals>.decorate_context(*args, **kwargs)
    113 @functools.wraps(func)
    114 def decorate_context(*args, **kwargs):
    115     with ctx_factory():
--> 116         return func(*args, **kwargs)

File /opt/conda/envs/gigaam/lib/python3.10/site-packages/nemo/collections/asr/models/rnnt_models.py:286, in EncDecRNNTModel.transcribe(self, paths2audio_files, batch_size, return_hypotheses, partial_hypothesis, num_workers, channel_selector, augmentor, verbose)
    284     for audio_file in paths2audio_files:
    285         entry = {'audio_filepath': audio_file, 'duration': 100000, 'text': ''}
--> 286         fp.write(json.dumps(entry) + '\n')
    288 config = {
    289     'paths2audio_files': paths2audio_files,
    290     'batch_size': batch_size,
   (...)
    293     'channel_selector': channel_selector,
    294 }
    296 if augmentor:

File /opt/conda/envs/gigaam/lib/python3.10/json/__init__.py:231, in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
    226 # cached encoder
    227 if (not skipkeys and ensure_ascii and
    228     check_circular and allow_nan and
    229     cls is None and indent is None and separators is None and
    230     default is None and not sort_keys and not kw):
--> 231     return _default_encoder.encode(obj)
    232 if cls is None:
    233     cls = JSONEncoder

File /opt/conda/envs/gigaam/lib/python3.10/json/encoder.py:199, in JSONEncoder.encode(self, o)
    195         return encode_basestring(o)
    196 # This doesn't pass the iterator directly to ''.join() because the
    197 # exceptions aren't as detailed.  The list call should be roughly
    198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
    200 if not isinstance(chunks, (list, tuple)):
    201     chunks = list(chunks)

File /opt/conda/envs/gigaam/lib/python3.10/json/encoder.py:257, in JSONEncoder.iterencode(self, o, _one_shot)
    252 else:
    253     _iterencode = _make_iterencode(
    254         markers, self.default, _encoder, self.indent, floatstr,
    255         self.key_separator, self.item_separator, self.sort_keys,
    256         self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)

File /opt/conda/envs/gigaam/lib/python3.10/json/encoder.py:179, in JSONEncoder.default(self, o)
    160 def default(self, o):
    161     """Implement this method in a subclass such that it returns
    162     a serializable object for ``o``, or calls the base implementation
    163     (to raise a ``TypeError``).
   (...)
    177 
    178     """
--> 179     raise TypeError(f'Object of type {o.__class__.__name__} '
    180                     f'is not JSON serializable')

TypeError: Object of type ndarray is not JSON serializable

According segment_audio function, segments are numpy array. But method model.transcribe waits paths.

Can you fix mistake in example and give code example to process long audios?

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

1 participant