question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object of type 'LazyFilter' has no len()

See original GitHub issue

I’m running into this weird issue, and I’m not sure why adding manifests should create a lazy iterator?

In [5]: m = prepare_ali_meeting('/export/c01/corpora6/AliMeeting')
Preparing Train: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 209/209 [02:56<00:00,  1.19it/s]
WARNING:root:Removed 241 supervisions starting after the end of the recording.
WARNING:root:Trimmed 5 supervisions exceeding the end of the recording.
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1019_M4026 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1019_M4028 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1019_M4030 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 4 supervisions that start at 0 for recording R1019_M4031 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1019_M4033 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1019_M4035 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1019_M4039 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1019_M4041 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1019_M4043 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1019_M4051 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 4 supervisions that start at 0 for recording R1019_M4052 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1021_M1935 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1021_M1942 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1021_M1944 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1021_M1959 (channel 0). Did you forget to set supervision start times?
WARNING:root:SupervisionSet contains 2 supervisions that start at 0 for recording R1021_M1961 (channel 0). Did you forget to set supervision start times?
Preparing Eval: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 8/8 [00:00<00:00, 10.20it/s]
Preparing Test: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 20/20 [00:01<00:00, 11.17it/s]

In [6]: s = m["eval"]["supervisions"]

In [7]: s1 = s.filter(lambda seg: seg.duration >= 0.5)

In [8]: len(s1)
Out[8]: 5193

In [9]: s = m["eval"]["supervisions"] + m["test"]["supervisions"]

In [10]: s1 = s.filter(lambda seg: seg.duration >= 0.5)
/export/c07/draj/lhotse/lhotse/lazy.py:327: UserWarning: A lambda was passed to LazyFilter: it may prevent you from forking this process. If you experience issues with num_workers > 0 in torch.utils.data.DataLoader, try passing a regular function instead.
  "A lambda was passed to LazyFilter: it may prevent you from forking this process. "

In [11]: len(s1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-a700e8f68e2d> in <module>
----> 1 len(s1)

/export/c07/draj/lhotse/lhotse/supervision.py in __len__(self)
    815
    816     def __len__(self) -> int:
--> 817         return len(self.segments)

TypeError: object of type 'LazyFilter' has no len()

Any suggestions?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
pzelaskocommented, May 19, 2022

we can either

  1. replace some integrity checks/fixes like remove_missing_recordings_and_supervisions with a two-pass strategy that first iterates to get the sets of compatible/incompatible IDs, and in the second pass filters out the incompatible ones.

or

  1. read everything into memory with manifest.to_eager() (will break for people with not enough CPU RAM and large data)
1reaction
pzelaskocommented, Apr 28, 2022

You can call .to_eager() on the resulting manifest to evaluate the expression. I started moving multiple operations to lazy evaluation a while ago, the only downside I can see is missing len. It’s just an extra function call away and for that we get memory-friendly behavior by default.

Read more comments on GitHub >

github_iconTop Results From Across the Web

object of type 'filter' has no len() [duplicate] - python
This is one of the major gotchas in switching from Python2 to Python3. filter returns an iterator rather than a list. I don't...
Read more >
TypeError: object of type 'filter' has no len() in Python
The Python TypeError: object of type 'filter' has no len() occurs when we pass a `filter` object to the `len()` function.
Read more >
Fix 'filter' object has no len () Β· 5d6f5eb7ab - karbor - OpenDev
Karbor has a python3 compatibility issue where it will fail with: TypeError: object of type 'filter' has no len(). 'filter' is a list...
Read more >
object of type 'builtin_function_or_method' has no len()
For the following code in section 4/11 of PygLatin. My program runs but once a word is typed then you pressed enter this...
Read more >
TypeError: object of type 'Token' has no len() Β· Issue #2826
TypeError: object of type 'Token' has no len() #2826. Closed. Ihebzayen opened this issue on Jun 20 Β· 12 comments.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found