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

Context must be initialized first #139

Closed
fcogidi opened this issue Mar 4, 2021 · 1 comment
Closed

Context must be initialized first #139

fcogidi opened this issue Mar 4, 2021 · 1 comment

Comments

@fcogidi
Copy link

fcogidi commented Mar 4, 2021

Hello,

I am working on a project to write videos to TFRecord format. I recently ran into an issue where I cannot get frames due to this error: Context must be initialized first. Here is a snippet of my code:

try:
  decord.bridge.set_bridge('tensorflow')
  vr = decord.VideoReader(path, ctx=decord.cpu(0))
  fps = math.ceil(vr.get_avg_fps())
  num_frames = min(len(vr), fps*10) # get at most 10 seconds of video
  frames = vr.get_batch(range(num_frames))
except Exception as e:
  logging.info(e)
  continue

This code is inside a loop, which is inside a function that is called by the multiprocessing.Pool.apply_async method. With a slight modification (removing the continue keyword), this code snippet works outside a loop, in a separate function. I need to be able to skip videos that can't be decoded, and it's easier to do that in a loop than in a function.

What could be going wrong and how do I get around it?

PS: I'm using TensorFlow==2.4.1 and decord==0.5.2

@zhreshold
Copy link
Member

related to #132

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

2 participants