Skip to content

Commit

Permalink
[auto] fix dataset agg in response to pandas>=1.3 (#1677)
Browse files Browse the repository at this point in the history
* fix dataset agg

* lint

* fix

* skip voc seg

* import
  • Loading branch information
zhreshold authored Jul 13, 2021
1 parent 8c75fa7 commit 1a22e0c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions gluoncv/auto/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,9 @@ def pack(self):
rois_columns = ['class', 'xmin', 'ymin', 'xmax', 'ymax', 'difficult']
image_attr_columns = ['width', 'height']
new_df = self.groupby(['image'], as_index=False).agg(list).reset_index(drop=True)
new_df['rois'] = new_df.agg(
lambda y: [{k : y[new_df.columns.get_loc(k)][i] for k in rois_columns if k in new_df.columns} \
for i in range(len(y[new_df.columns.get_loc('class')]))], axis=1)
new_df['rois'] = new_df.apply(
lambda y: [{k : y.loc[k][i] for k in rois_columns if k in new_df.columns} \
for i in range(len(y.loc['class']))], axis=1)
new_df = new_df.drop(rois_columns, axis=1, errors='ignore')
new_df['image_attr'] = new_df.agg(
lambda y: {k : y[new_df.columns.get_loc(k)][0] for k in image_attr_columns if k in new_df.columns}, axis=1)
Expand Down
10 changes: 10 additions & 0 deletions tests/auto/test_auto_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import tempfile
import pandas as pd
from gluoncv.auto.data.dataset import ImageClassificationDataset
from gluoncv.auto.data.dataset import ObjectDetectionDataset


def test_image_datasets_from_csv():
N = 10
Expand All @@ -43,6 +45,14 @@ def gen_fake_data(dir_name):
d2 = ImageClassificationDataset(abnormal_csv, image_column='some_image', label_column='some_label')
d2 = ImageClassificationDataset.from_csv(abnormal_csv, image_column='some_image', label_column='some_label')

def test_object_detection_data():
df = ObjectDetectionDataset.from_voc('https://autogluon.s3.amazonaws.com/datasets/tiny_motorbike.zip')
if df.is_packed():
df2 = df.unpack().pack()
else:
df2 = df.pack().unpack()
assert df2.equals(df), 'pack unpack inconsistent'

if __name__ == '__main__':
import nose
nose.runmodule()
2 changes: 1 addition & 1 deletion tests/py3_auto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
- matplotlib
- tqdm
- pillow
- pandas
- pandas==1.3
- pip:
- https://repo.mxnet.io/dist/python/cu100mkl/mxnet_cu100mkl-1.6.0b20191010-py2.py3-none-manylinux1_x86_64.whl
- coverage-badge
Expand Down
2 changes: 2 additions & 0 deletions tests/unittests/test_data_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from gluoncv import data
from .tiny_datasets import COCODetectionTiny, COCOInstanceTiny, VOCDetectionTiny, VOCSegmentationTiny
import os.path as osp
import unittest


def test_pascal_voc_detection():
Expand Down Expand Up @@ -48,6 +49,7 @@ def test_coco_instance():
index = np.random.randint(0, len(val))
_ = val[index]

@unittest.skip("temporarily disabled due to drawing compatibility")
def test_voc_segmentation():

# use valid only, loading training split is very slow
Expand Down

0 comments on commit 1a22e0c

Please sign in to comment.