ocean-data-factory-sweden / kso

Notebooks to upload/download marine footage, connect to a citizen science project, train machine learning models and publish marine biological observations.
GNU General Public License v3.0
4 stars 12 forks source link

Tutorial 4 frame extraction issue #258

Closed jannesgg closed 9 months ago

jannesgg commented 9 months ago

Cannot generate more than 10 frames/ movie in tutorial 4 in the KSO project, else error occurs

input:

# Generate suitable frames for upload by modifying initial frames
pp.generate_custom_frames(
    input_path=input_folder.selected,
    output_path=output_folder.selected,
    backend="av",
    skip_start=120,
    skip_end=120,
    num_frames=100,
    frames_skip=None,
)

Output:

WARNING:libav.mov,mp4,m4a,3gp,3g2,mj2:st: 0 edit list: 1 Missing key frame while searching for timestamp: 0
WARNING:libav.mov,mp4,m4a,3gp,3g2,mj2:st: 0 edit list 1 Cannot find an index entry before timestamp: 0.
WARNING:libav.mov,mp4,m4a,3gp,3g2,mj2:st: 0 edit list: 1 Missing key frame while searching for timestamp: 0
WARNING:libav.mov,mp4,m4a,3gp,3g2,mj2:st: 0 edit list: 1 Missing key frame while searching for timestamp: 0
WARNING:libav.mov,mp4,m4a,3gp,3g2,mj2:st: 0 edit list 1 Cannot find an index entry before timestamp: 0.
WARNING:libav.mov,mp4,m4a,3gp,3g2,mj2:st: 0 edit list 1 Cannot find an index entry before timestamp: 0.
---------------------------------------------------------------------------
RemoteTraceback                           Traceback (most recent call last)
RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 51, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
  File "/usr/src/app/kso/kso_utils/kso_utils/widgets.py", line 1229, in extract_custom_frames
    frames_to_extract = random.sample(
  File "/usr/lib/python3.8/random.py", line 363, in sample
    raise ValueError("Sample larger than population or is negative")
ValueError: Sample larger than population or is negative
"""

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
File /usr/src/app/kso/kso_utils/kso_utils/project.py:891, in ProjectProcessor.generate_custom_frames.<locals>.on_button_clicked(b)
    880 def on_button_clicked(b):
    881     movie_files = sorted(
    882         [
    883             f
   (...)
    888         ]
    889     )
--> 891     results = g_utils.parallel_map(
    892         kso_widgets.extract_custom_frames,
    893         movie_files,
    894         args=(
    895             [output_path] * len(movie_files),
    896             [skip_start] * len(movie_files),
    897             [skip_end] * len(movie_files),
    898             [num_frames] * len(movie_files),
    899             [frames_skip] * len(movie_files),
    900             [backend] * len(movie_files),
    901         ),
    902     )
    903     if len(results) > 0:
    904         self.frames_to_upload_df = pd.concat(results)

File /usr/src/app/kso/kso_utils/kso_utils/general.py:84, in parallel_map(func, iterable, args)
     67 """
     68 The function `parallel_map` uses multiprocessing to apply a given function to each element of an
     69 iterable in parallel.
   (...)
     81 is optional and can be used to pass additional arguments to the function `func`.
     82 """
     83 with multiprocessing.Pool() as pool:
---> 84     results = pool.starmap(func, zip(iterable, *args))
     85 return results

File /usr/lib/python3.8/multiprocessing/pool.py:372, in Pool.starmap(self, func, iterable, chunksize)
    366 def starmap(self, func, iterable, chunksize=None):
    367     '''
    368     Like `map()` method but the elements of the `iterable` are expected to
    369     be iterables as well and will be unpacked as arguments. Hence
    370     `func` and (a, b) becomes func(a, b).
    371     '''
--> 372     return self._map_async(func, iterable, starmapstar, chunksize).get()

File /usr/lib/python3.8/multiprocessing/pool.py:771, in ApplyResult.get(self, timeout)
    769     return self._value
    770 else:
--> 771     raise self._value

ValueError: Sample larger than population or is negative

Expected behaviour:


In theory it should extract the specified amount of frames for each movie, but such was not the way
victor-wildlife commented 9 months ago

@Bergylta What project are you running this tut#4 on?

Bergylta commented 9 months ago

@victor-wildlife This was running the KSO project