Hey, first post here, so let me know if I’m omitting necessary information.
=== Software ===
python version : 3.7.0
fastai version : 1.0.25.dev0
torch version : 1.0.0.dev20181116
torch cuda ver
torch cuda is : **Not available**
=== Hardware ===
No GPUs available
=== Environment ===
platform : Linux-4.4.0-53-generic-x86_64-with-debian-stretch-sid
distro : #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016
conda env : fastai-cpu
python : /home/username/anaconda3/envs/fastai-cpu/bin/python
sys.path :
/home/username/anaconda3/envs/fastai-cpu/lib/python37.zip
/home/username/anaconda3/envs/fastai-cpu/lib/python3.7
/home/username/anaconda3/envs/fastai-cpu/lib/python3.7/lib-dynload
/home/username/anaconda3/envs/fastai-cpu/lib/python3.7/site-packages
/home/username/anaconda3/envs/fastai-cpu/lib/python3.7/site-packages/IPython/extensions
no supported gpus found on this system
I’m trying to do object detection on my own dataset, but I have so far been unable to load the dataset correctly. I have the following code and when I run it dataset.show_batch
will fail for certain images.
import fastai
from fastai.vision import (data as Data,
learner as Learner,
models as Models,
transform as Transform)
from torch import nn
from pathlib import Path
import matplotlib.pyplot as plt
import pandas as pd
import json
import collections
import numpy as npPATH = Path(‘/home/username/Dropbox/workspace/fastai/data/animal’)
train_json = json.load((PATH / ‘dataset.json’).open())IMAGES,ANNOTATIONS,CATEGORIES = [‘images’, ‘annotations’, ‘categories’]
FILE_NAME,ID,IMG_ID,CAT_ID,BBOX = ‘file_name’,‘id’,‘image_id’,‘category_id’,‘bbox’cats = dict((o[ID], o[‘name’]) for o in train_json[CATEGORIES])
train_filenames = dict((o[ID], o[FILE_NAME]) for o in train_json[IMAGES])
train_ids = [o[ID] for o in train_json[IMAGES]]IMG_PATH = Path(‘/home/username/Dropbox/workspace/fastai/data/animal’)
id2cat = list(cats.values())
def get_train_anno_by_filename(train_json):
train_anno = collections.defaultdict(lambda:)
for o in train_json[ANNOTATIONS]:
if not o[‘ignore’]:
bb = o[BBOX]
bb = list([bb[1], bb[0], bb[3]+bb[1]-1, bb[2]+bb[0]-1])
fn = train_filenames[o[IMG_ID]]
cat = id2cat[o[CAT_ID]]
train_anno[fn].append((bb, cat))
fn2anno = {}
for fn, targets in train_anno.items():
fn2anno[fn] = [list(e) for e in zip(*targets)]
return fn2annofn2anno = get_train_anno_by_filename(train_json)
df = pd.DataFrame(
{‘fn’: [train_filenames[i] for i in train_ids]},
columns=[‘fn’]
)tfms = Transform.get_transforms(
xtra_tfms=Transform.rand_resize_crop(224)
)def get_y_func(o):
fn = Path(o).name
res = fn2anno[fn]
return resdataset = (Data.ObjectItemList.from_df(
df_reduced,
IMG_PATH
)
.random_split_by_pct()
.label_from_func(get_y_func)
.transform(tfms, tfm_y=True)
.databunch(bs=4, collate_fn=Data.bb_pad_collate))dataset.show_batch(rows=2, ds_type=Data.DatasetType.Valid, figsize=(6,6))
I get the following error
TypeError Traceback (most recent call last)
in
----> 1 dataset.show_batch(rows=2, ds_type=Data.DatasetType.Valid, figsize=(6,6))~/Dropbox/workspace/fastai/fastai/basic_data.py in show_batch(self, rows, ds_type, **kwargs)
119 if rows is None: rows = int(math.sqrt(len(b_idx)))
120 ds = dl.dataset
→ 121 ds[0][0].show_batch(b_idx, rows, ds, **kwargs)
122
123 @property~/Dropbox/workspace/fastai/fastai/data_block.py in getitem(self, idxs)
343 def getitem(self,idxs:Union[int,np.ndarray])->‘LabelList’:
344 if isinstance(try_int(idxs), int):
→ 345 if self.item is None: x,y = self.x[idxs],self.y[idxs]
346 else: x,y = self.item ,0
347 if self.tfms:~/Dropbox/workspace/fastai/fastai/data_block.py in getitem(self, idxs)
77
78 def getitem(self,idxs:int)->Any:
—> 79 if isinstance(try_int(idxs), int): return self.get(idxs)
80 else: return self.new(self.items[idxs], xtra=index_row(self.xtra, idxs))
81~/Dropbox/workspace/fastai/fastai/vision/data.py in get(self, i)
305
306 def get(self, i):
→ 307 return ImageBBox.create(*self.x.sizes[i], *self.items[i])
308
309 class ObjectItemList(ImageItemList):~/Dropbox/workspace/fastai/fastai/vision/image.py in create(cls, h, w, bboxes, labels, c2i, pad_idx)
→ 390 bboxes = tensor(bboxes).float()
391 tr_corners = torch.cat([bboxes[:,0][:,None], bboxes[:,3][:,None]], 1)
392 bl_corners = bboxes[:,1:3].flip(1)~/Dropbox/workspace/fastai/fastai/torch_core.py in tensor(x, *rest)
66 “Liketorch.as_tensor
, but handle lists too, and can pass multiple vector elements directly”
67 if len(rest): x = (x,)+rest
—> 68 return torch.tensor(x) if is_listy(x) else as_tensor(x)
69
70 def np_address(x:np.ndarray)->int:TypeError: can’t convert np.ndarray of type numpy.object_. The only supported types are: double, float, float16, int64, int32, and uint8.
When I print bboxes
before the program fails I consistently get [list(x, y, z, c)]
when it fails vs [[x, y, z, c]]
. So I can fix this problem by doing bboxes = [list(bbox) for bbox in bboxes], but I am very confused as to why this is an issue in the first place. All bounding boxes are made the same way for all images. Additionally, this only happens for the valid set, never for the train set.
Further more, if I do show_batch for the train set, the bounding boxes become displaced because of the transformations. This seems to be because of the rand_resize_crop transform. Is it a known issue that it does not work or am I doing something wrong?
Thanks:)