At least, thats what it looks like it’s doing, but I’m not sure.
My code:
pages_db = DataBlock(
blocks=(ImageBlock, BBoxBlock, BBoxLblBlock),
get_items=get_image_files,
splitter=RandomSplitter(),
get_y=[
lambda o: trn_df_bb_trim.loc[trn_df_bb_trim['name']==f'{o.stem}{o.suffix}','label'].values[0][0],
lambda o: trn_df_bb_trim.loc[trn_df_bb_trim['name']==f'{o.stem}{o.suffix}','label'].values[0][1]
],
item_tfms= Resize(512),
n_inp=1
)
#pages_dl = pages_db.dataloaders(TRN_DATA_PTH)
pages_db.summary(TRN_DATA_PTH, before_batch=None)
Fairly straightforward fastai code. The lambda’s I’ve verified are grabbing the boxes and the labels correctly from my pandas table.
The lead is this.
First, proof that the dataloader knows the bboxes aren’t emtpy:
Final sample: (PILImage mode=RGB size=1776x2808, TensorBBox([[ 860., 1805., 874., 1779.],
[ 813., 1781., 883., 1748.],
[1380., 2487., 1460., 2454.],
[ 813., 2569., 861., 2532.],
[ 280., 2560., 316., 2521.],
....
TensorMultiCategory([ 195, 160, 89, 80, 120, 80, 80, 37, 120, 80, 73, 45,
80, 44, 120, 108, 44, 149, 40, 89, 79, 108, 48, 73,
45, 44, 108, 79, 43, 98, 45, 873, 114, 53, 79, 89,
....
Then, the before_batch
Applying before_batch to the list of samples
Pipeline: bb_pad
starting from
[(TensorImage of size 3x512x512, TensorBBox of size 183x4, TensorMultiCategory of size 183), (TensorImage of size 3x512x512, TensorBBox of size 96x4, TensorMultiCategory of size 96), (TensorImage of size 3x512x512, TensorBBox of size 207x4, TensorMultiCategory of size 207), (TensorImage of size 3x512x512, TensorBBox of size 285x4, TensorMultiCategory of size 285)]
applying bb_pad gives
[(TensorImage of size 3x512x512, TensorBBox of size 0x4, TensorMultiCategory([], dtype=torch.int64)), (TensorImage of size 3x512x512, TensorBBox of size 0x4, TensorMultiCategory([], dtype=torch.int64)), (TensorImage of size 3x512x512, TensorBBox of size 0x4, TensorMultiCategory([], dtype=torch.int64)), (TensorImage of size 3x512x512, TensorBBox of size 0x4, TensorMultiCategory([], dtype=torch.int64))]
The before_batch look at the sample fills me with confidence since the TensorBBox and the TensorMultiCategory match in non-zero size. However, bb_pad appears to wreak havoc.
Things to note:
- Both
summary
anddataloaders
execute with no problems. - I can do
show_batch
and get an image back with zero bounding boxes or labels
I know that bb_pad is added as a before_batch operation thanks to BBoxBlock, but unsure what the heck it’s doing to nullify all my labels. Is the item transform not being applied to the targets in a way thats making all the bounding boxes empty?
Meanwhile, I’m investigating how bb_pad
operates on its parameters …