I have a custom datastore which essentially loads a list of row
s of type Row
. Each Row
instance has corresponding annotations
of type AnnotationSpec
s.
class Row(object):
def __init__(self, patient, image_path, left_eye, annotation_specs=None):
self.patient = patient
self.image_path = image_path
self.left_eye = left_eye
self.annotation_specs = annotation_specs
# Defines a list of ver
class AnnotationSpec(object):
def __init__(self, annotation_path, class_id, class_name, vertices):
self.annotation_path = annotation_path
self.class_id = class_id
self.class_name = class_name
self.vertices = vertices
I defined a DataBlock
which looks like this:
# Loads a list of rows, which have an `image_path` and a list of `annotations` associated.
rows = load_rows()
print('Loaded records %s' % (len(rows)))
def get_items(path):
return rows
def load_image(row):
image = cv2.imread(row.image_path, cv2.COLOR_BGR2RGB)
return image
def _fill_vertices(mask_data, vertices, value):
if vertices is not None:
normalized = np.array(vertices)
coordinates = np.multiply(normalized, np.array([SRC_IMAGE_WIDTH, SRC_IMAGE_HEIGHT]))
coordinates = np.asarray(coordinates, dtype='int32')
cv2.fillConvexPoly(mask_data, coordinates, [value, value])
def load_masks(row):
mask_data = np.zeros((SRC_IMAGE_HEIGHT, SRC_IMAGE_WIDTH), dtype='int32')
eyelids = list(filter(lambda spec: spec.class_name == 'eyelid', row.annotation_specs))
pupils = list(filter(lambda spec: spec.class_name == 'pupil', row.annotation_specs))
# Draw eyelids first
if len(eyelids) > 0:
eyelid = eyelids[0]
_fill_vertices(mask_data, eyelid.vertices, 2)
# Overlay Pupils on Eyelids
if len(pupils) > 0:
pupil = pupils[0]
_fill_vertices(mask_data, pupil.vertices, 3)
return numpy.asarray(mask_data, dtype='uint8')
block = DataBlock(
# I have 3 codes 0 = background, 2 = eyelid, 3 = pupil
blocks=(ImageBlock(), MaskBlock((0, 2, 3))),
get_items=get_items,
splitter=RandomSplitter(),
getters=[
load_image, load_masks
],
)
loaders = block.dataloaders(Path('.'), bs=4)
loaders.show_batch(max_n=4)
This works as expected, and my loaders
instance loads the images.
Now when I try and train a model like so:
learner = unet_learner(loaders, resnet34)
learner.fine_tune(1)
I run into an error:
THCudaCheck FAIL file=/pytorch/aten/src/THC/generic/THCTensorMath.cu line=26 error=710 : device-side assert triggered
/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:106: void cunn_ClassNLLCriterion_updateOutput_kernel(Dtype *, Dtype *, Dtype *, long *, Dtype *, int, int, int, int, long) [with Dtype = float, Acctype = float]: block: [0,0,0], thread: [21,0,0] Assertion `t >= 0 && t < n_classes` failed.
Any ideas on what might be going on?
Thanks,
Rahul