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

StopIteration Error while running inference on the frames #76

Open
mohsin-ashraf opened this issue Jan 30, 2024 · 3 comments
Open

StopIteration Error while running inference on the frames #76

mohsin-ashraf opened this issue Jan 30, 2024 · 3 comments

Comments

@mohsin-ashraf
Copy link

mohsin-ashraf commented Jan 30, 2024

Hi, team Pixeltable. I am working with the Pixeltable frame views. While the view gets created successfully when I try to access it I get to access the frames of the view I get the following error.

---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
File /opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/exprs/row_builder.py:306, in RowBuilder.eval(self, data_row, ctx, profile, ignore_errors)
    305 start_time = time.perf_counter()
--> 306 expr.eval(data_row, self)
    307 if profile is not None:

File /opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/exprs/column_ref.py:90, in ColumnRef.eval(self, data_row, row_builder)
     89 self.iterator.set_pos(data_row.pk[self.pos_idx])
---> 90 res = next(self.iterator)
     91 data_row[self.slot_idx] = res[self.col.name]

File /opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/iterators/video.py:64, in FrameIterator.__next__(self)
     63     self.video_reader = None
---> 64     raise StopIteration
     65 if pos_frame % self.frame_freq == 0:

StopIteration: 

During handling of the above exception, another exception occurred:

ExprEvalError                             Traceback (most recent call last)
File /opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/dataframe.py:327, in DataFrame.collect(self)
    326 result_rows = []
--> 327 for data_row in self._exec():
    328     result_row = [data_row[e.slot_idx] for e in self._select_list_exprs]

File /opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/dataframe.py:291, in DataFrame._exec(self)
    290 try:
--> 291     for row_batch in plan:
    292         for data_row in row_batch:

File /opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/exec/expr_eval_node.py:45, in ExprEvalNode.__next__(self)
     44 for cohort in self.cohorts:
---> 45     self._exec_cohort(cohort, input_batch)
     46 _logger.debug(f'ExprEvalNode: returning {len(input_batch)} rows')

File /opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/exec/expr_eval_node.py:144, in ExprEvalNode._exec_cohort(self, cohort, rows)
    143     for row_idx in range(batch_start_idx, batch_start_idx + num_batch_rows):
--> 144         self.row_builder.eval(
    145             rows[row_idx], segment_ctx, self.ctx.profile, ignore_errors=self.ctx.ignore_errors)
    146 else:

File /opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/exprs/row_builder.py:315, in RowBuilder.eval(self, data_row, ctx, profile, ignore_errors)
    314 input_vals = [data_row[d.slot_idx] for d in expr.dependencies()]
--> 315 raise excs.ExprEvalError(
    316     expr, f'expression {expr}', data_row.get_exc(expr.slot_idx), exc_tb, input_vals, 0)

ExprEvalError: (<pixeltable.exprs.column_ref.ColumnRef object at 0x28c4a0d90>, 'expression frame', StopIteration(), <traceback object at 0x28c36af40>, [], 0)

During handling of the above exception, another exception occurred:

Error                                     Traceback (most recent call last)
Cell In[22], line 1
----> 1 view.select(view.frame).show(5)

File /opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/dataframe.py:300, in DataFrame.show(self, n)
    298 def show(self, n: int = 20) -> DataFrameResultSet:
    299     assert n is not None
--> 300     return self.limit(n).collect()

File /opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/dataframe.py:347, in DataFrame.collect(self)
    345         # [-1:0:-1]: leave out entry 0 and reverse order, so that the most recent frame is at the top
    346         msg += f'\nStack:\n{nl.join(stack_trace[-1:1:-1])}'
--> 347     raise exc.Error(msg)
    348 except sql.exc.DBAPIError as e:
    349     raise exc.Error(f'Error during SQL execution:\n{e}')

Error: In row 0 the expression frame encountered exception StopIteration:

Stack:
  File "/opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/iterators/video.py", line 64, in __next__
    raise StopIteration```


Accessing other columns works fine. Also this error is not occurring for all the views but for some. Basically I am working with 3 views, and out of these views I get this error for sometime all views, one of the view, this error is very random.

@mohsin-ashraf
Copy link
Author

For some views which gets generated properly, when I try to inference on them to get the bounding boxes I get the same error

python inference/pre_annotate_view.py -v deployment_33_fps_0_5_tp 
2024-01-30 18:35:03,397 INFO pixeltable env.py:188: found database postgresql://postgres:@/pixeltable?host=/Users/mohsinashraf/.pixeltable/pgdata
Computing cells: 362cells [02:58,  2.02cells/s]                                                                                                                                                                                                      
added 273 column values with 0 errors
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/exprs/row_builder.py", line 306, in eval
    expr.eval(data_row, self)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/exprs/column_ref.py", line 90, in eval
    res = next(self.iterator)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/iterators/video.py", line 64, in __next__
    raise StopIteration
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/dataframe.py", line 327, in collect
    for data_row in self._exec():
  File "/opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/dataframe.py", line 291, in _exec
    for row_batch in plan:
  File "/opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/exec/expr_eval_node.py", line 45, in __next__
    self._exec_cohort(cohort, input_batch)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/exec/expr_eval_node.py", line 144, in _exec_cohort
    self.row_builder.eval(
  File "/opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/exprs/row_builder.py", line 315, in eval
    raise excs.ExprEvalError(
pixeltable.exceptions.ExprEvalError: (<pixeltable.exprs.column_ref.ColumnRef object at 0x16e042980>, 'expression frame', StopIteration(), <traceback object at 0x16e17f680>, [], 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/mohsinashraf/obvio/ObvioEngine/vision/infra/pixeltable/inference/pre_annotate_view.py", line 36, in <module>
    df = view.select(*eval(columns)).collect().to_pandas()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/dataframe.py", line 347, in collect
    raise exc.Error(msg)
pixeltable.exceptions.Error: In row 0 the expression frame encountered exception StopIteration:

Stack:
  File "/opt/homebrew/Caskroom/miniconda/base/envs/pixeltable/lib/python3.10/site-packages/pixeltable/iterators/video.py", line 64, in __next__
    raise StopIteration

Code for inference is given below.


@pxt.udf(return_type=pxt.JsonType(), param_types=[pxt.ImageType()])
def detection_in_coco(img):
    img = np.array(img)
    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
    detections = detector.detect(img)
    pre_annotations = []
    if detections:
        for detection in detections:
            bbox = detection[:4]
            conf, label = detection[4:]
            if int(label) not in (0,2,6,8): continue
            bbox = list(map(int, bbox))
            x,y,w,h = bbox
            pre_annotations.append({
                'bbox': [x,y,w,h],
                'category': CATEGORY_MAP[int(label)],
            })
    return pre_annotations

@mkornacker
Copy link
Collaborator

mkornacker commented Jan 30, 2024

Could you please also include the table and view definitions and the queries you're running?

@mkornacker mkornacker closed this as not planned Won't fix, can't repro, duplicate, stale Feb 10, 2024
@orm011 orm011 reopened this Apr 18, 2024
@orm011
Copy link
Collaborator

orm011 commented Apr 18, 2024

We are looking into this issue, we think we have found the problem. We'll let you know

@orm011 orm011 closed this as completed Apr 18, 2024
@orm011 orm011 reopened this Apr 18, 2024
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

3 participants