Python datasets.imagenet() Examples
The following are 12
code examples of datasets.imagenet().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
datasets
, or try the search function
.
Example #1
Source File: imagenet.py From cascade-rcnn_Pytorch with MIT License | 5 votes |
def _load_imagenet_annotation(self, index): """ Load image and bounding boxes info from txt files of imagenet. """ filename = os.path.join(self._data_path, 'Annotations', self._image_set, index + '.xml') # print 'Loading: {}'.format(filename) def get_data_from_tag(node, tag): return node.getElementsByTagName(tag)[0].childNodes[0].data with open(filename) as f: data = minidom.parseString(f.read()) objs = data.getElementsByTagName('object') num_objs = len(objs) boxes = np.zeros((num_objs, 4), dtype=np.uint16) gt_classes = np.zeros((num_objs), dtype=np.int32) overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32) # Load object bounding boxes into a data frame. for ix, obj in enumerate(objs): x1 = float(get_data_from_tag(obj, 'xmin')) y1 = float(get_data_from_tag(obj, 'ymin')) x2 = float(get_data_from_tag(obj, 'xmax')) y2 = float(get_data_from_tag(obj, 'ymax')) cls = self._wnid_to_ind[ str(get_data_from_tag(obj, "name")).lower().strip()] boxes[ix, :] = [x1, y1, x2, y2] gt_classes[ix] = cls overlaps[ix, cls] = 1.0 overlaps = scipy.sparse.csr_matrix(overlaps) return {'boxes' : boxes, 'gt_classes': gt_classes, 'gt_overlaps' : overlaps, 'flipped' : False}
Example #2
Source File: imagenet.py From pytorch-detect-to-track with MIT License | 5 votes |
def _load_imagenet_annotation(self, index): """ Load image and bounding boxes info from txt files of imagenet. """ filename = os.path.join(self._data_path, 'Annotations', self._image_set, index + '.xml') # print 'Loading: {}'.format(filename) def get_data_from_tag(node, tag): return node.getElementsByTagName(tag)[0].childNodes[0].data with open(filename) as f: data = minidom.parseString(f.read()) objs = data.getElementsByTagName('object') num_objs = len(objs) boxes = np.zeros((num_objs, 4), dtype=np.uint16) gt_classes = np.zeros((num_objs), dtype=np.int32) overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32) # Load object bounding boxes into a data frame. for ix, obj in enumerate(objs): x1 = float(get_data_from_tag(obj, 'xmin')) y1 = float(get_data_from_tag(obj, 'ymin')) x2 = float(get_data_from_tag(obj, 'xmax')) y2 = float(get_data_from_tag(obj, 'ymax')) cls = self._wnid_to_ind[ str(get_data_from_tag(obj, "name")).lower().strip()] boxes[ix, :] = [x1, y1, x2, y2] gt_classes[ix] = cls overlaps[ix, cls] = 1.0 overlaps = scipy.sparse.csr_matrix(overlaps) return {'boxes' : boxes, 'gt_classes': gt_classes, 'gt_overlaps' : overlaps, 'flipped' : False}
Example #3
Source File: imagenet.py From RFCN_CoupleNet.pytorch with MIT License | 5 votes |
def _load_imagenet_annotation(self, index): """ Load image and bounding boxes info from txt files of imagenet. """ filename = os.path.join(self._data_path, 'Annotations', self._image_set, index + '.xml') # print 'Loading: {}'.format(filename) def get_data_from_tag(node, tag): return node.getElementsByTagName(tag)[0].childNodes[0].data with open(filename) as f: data = minidom.parseString(f.read()) objs = data.getElementsByTagName('object') num_objs = len(objs) boxes = np.zeros((num_objs, 4), dtype=np.uint16) gt_classes = np.zeros((num_objs), dtype=np.int32) overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32) # Load object bounding boxes into a data frame. for ix, obj in enumerate(objs): x1 = float(get_data_from_tag(obj, 'xmin')) y1 = float(get_data_from_tag(obj, 'ymin')) x2 = float(get_data_from_tag(obj, 'xmax')) y2 = float(get_data_from_tag(obj, 'ymax')) cls = self._wnid_to_ind[ str(get_data_from_tag(obj, "name")).lower().strip()] boxes[ix, :] = [x1, y1, x2, y2] gt_classes[ix] = cls overlaps[ix, cls] = 1.0 overlaps = scipy.sparse.csr_matrix(overlaps) return {'boxes' : boxes, 'gt_classes': gt_classes, 'gt_overlaps' : overlaps, 'flipped' : False}
Example #4
Source File: imagenet.py From fpn.pytorch with MIT License | 5 votes |
def _load_imagenet_annotation(self, index): """ Load image and bounding boxes info from txt files of imagenet. """ filename = os.path.join(self._data_path, 'Annotations', self._image_set, index + '.xml') # print 'Loading: {}'.format(filename) def get_data_from_tag(node, tag): return node.getElementsByTagName(tag)[0].childNodes[0].data with open(filename) as f: data = minidom.parseString(f.read()) objs = data.getElementsByTagName('object') num_objs = len(objs) boxes = np.zeros((num_objs, 4), dtype=np.uint16) gt_classes = np.zeros((num_objs), dtype=np.int32) overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32) # Load object bounding boxes into a data frame. for ix, obj in enumerate(objs): x1 = float(get_data_from_tag(obj, 'xmin')) y1 = float(get_data_from_tag(obj, 'ymin')) x2 = float(get_data_from_tag(obj, 'xmax')) y2 = float(get_data_from_tag(obj, 'ymax')) cls = self._wnid_to_ind[ str(get_data_from_tag(obj, "name")).lower().strip()] boxes[ix, :] = [x1, y1, x2, y2] gt_classes[ix] = cls overlaps[ix, cls] = 1.0 overlaps = scipy.sparse.csr_matrix(overlaps) return {'boxes' : boxes, 'gt_classes': gt_classes, 'gt_overlaps' : overlaps, 'flipped' : False}
Example #5
Source File: imagenet.py From FPN_Pytorch with MIT License | 5 votes |
def _load_imagenet_annotation(self, index): """ Load image and bounding boxes info from txt files of imagenet. """ filename = os.path.join(self._data_path, 'Annotations', self._image_set, index + '.xml') # print 'Loading: {}'.format(filename) def get_data_from_tag(node, tag): return node.getElementsByTagName(tag)[0].childNodes[0].data with open(filename) as f: data = minidom.parseString(f.read()) objs = data.getElementsByTagName('object') num_objs = len(objs) boxes = np.zeros((num_objs, 4), dtype=np.uint16) gt_classes = np.zeros((num_objs), dtype=np.int32) overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32) # Load object bounding boxes into a data frame. for ix, obj in enumerate(objs): x1 = float(get_data_from_tag(obj, 'xmin')) y1 = float(get_data_from_tag(obj, 'ymin')) x2 = float(get_data_from_tag(obj, 'xmax')) y2 = float(get_data_from_tag(obj, 'ymax')) cls = self._wnid_to_ind[ str(get_data_from_tag(obj, "name")).lower().strip()] boxes[ix, :] = [x1, y1, x2, y2] gt_classes[ix] = cls overlaps[ix, cls] = 1.0 overlaps = scipy.sparse.csr_matrix(overlaps) return {'boxes' : boxes, 'gt_classes': gt_classes, 'gt_overlaps' : overlaps, 'flipped' : False}
Example #6
Source File: imagenet.py From pytorch-lighthead with MIT License | 5 votes |
def _load_imagenet_annotation(self, index): """ Load image and bounding boxes info from txt files of imagenet. """ filename = os.path.join(self._data_path, 'Annotations', self._image_set, index + '.xml') # print 'Loading: {}'.format(filename) def get_data_from_tag(node, tag): return node.getElementsByTagName(tag)[0].childNodes[0].data with open(filename) as f: data = minidom.parseString(f.read()) objs = data.getElementsByTagName('object') num_objs = len(objs) boxes = np.zeros((num_objs, 4), dtype=np.uint16) gt_classes = np.zeros((num_objs), dtype=np.int32) overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32) # Load object bounding boxes into a data frame. for ix, obj in enumerate(objs): x1 = float(get_data_from_tag(obj, 'xmin')) y1 = float(get_data_from_tag(obj, 'ymin')) x2 = float(get_data_from_tag(obj, 'xmax')) y2 = float(get_data_from_tag(obj, 'ymax')) cls = self._wnid_to_ind[ str(get_data_from_tag(obj, "name")).lower().strip()] boxes[ix, :] = [x1, y1, x2, y2] gt_classes[ix] = cls overlaps[ix, cls] = 1.0 overlaps = scipy.sparse.csr_matrix(overlaps) return {'boxes' : boxes, 'gt_classes': gt_classes, 'gt_overlaps' : overlaps, 'flipped' : False}
Example #7
Source File: imagenet.py From faster-rcnn.pytorch with MIT License | 5 votes |
def _load_imagenet_annotation(self, index): """ Load image and bounding boxes info from txt files of imagenet. """ filename = os.path.join(self._data_path, 'Annotations', self._image_set, index + '.xml') # print 'Loading: {}'.format(filename) def get_data_from_tag(node, tag): return node.getElementsByTagName(tag)[0].childNodes[0].data with open(filename) as f: data = minidom.parseString(f.read()) objs = data.getElementsByTagName('object') num_objs = len(objs) boxes = np.zeros((num_objs, 4), dtype=np.uint16) gt_classes = np.zeros((num_objs), dtype=np.int32) overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32) # Load object bounding boxes into a data frame. for ix, obj in enumerate(objs): x1 = float(get_data_from_tag(obj, 'xmin')) y1 = float(get_data_from_tag(obj, 'ymin')) x2 = float(get_data_from_tag(obj, 'xmax')) y2 = float(get_data_from_tag(obj, 'ymax')) cls = self._wnid_to_ind[ str(get_data_from_tag(obj, "name")).lower().strip()] boxes[ix, :] = [x1, y1, x2, y2] gt_classes[ix] = cls overlaps[ix, cls] = 1.0 overlaps = scipy.sparse.csr_matrix(overlaps) return {'boxes' : boxes, 'gt_classes': gt_classes, 'gt_overlaps' : overlaps, 'flipped' : False}
Example #8
Source File: imagenet.py From One-Shot-Object-Detection with MIT License | 5 votes |
def _load_imagenet_annotation(self, index): """ Load image and bounding boxes info from txt files of imagenet. """ filename = os.path.join(self._data_path, 'Annotations', self._image_set, index + '.xml') # print 'Loading: {}'.format(filename) def get_data_from_tag(node, tag): return node.getElementsByTagName(tag)[0].childNodes[0].data with open(filename) as f: data = minidom.parseString(f.read()) objs = data.getElementsByTagName('object') num_objs = len(objs) boxes = np.zeros((num_objs, 4), dtype=np.uint16) gt_classes = np.zeros((num_objs), dtype=np.int32) overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32) # Load object bounding boxes into a data frame. for ix, obj in enumerate(objs): x1 = float(get_data_from_tag(obj, 'xmin')) y1 = float(get_data_from_tag(obj, 'ymin')) x2 = float(get_data_from_tag(obj, 'xmax')) y2 = float(get_data_from_tag(obj, 'ymax')) cls = self._wnid_to_ind[ str(get_data_from_tag(obj, "name")).lower().strip()] boxes[ix, :] = [x1, y1, x2, y2] gt_classes[ix] = cls overlaps[ix, cls] = 1.0 overlaps = scipy.sparse.csr_matrix(overlaps) return {'boxes' : boxes, 'gt_classes': gt_classes, 'gt_overlaps' : overlaps, 'flipped' : False}
Example #9
Source File: imagenet.py From bottom-up-features with MIT License | 5 votes |
def _load_imagenet_annotation(self, index): """ Load image and bounding boxes info from txt files of imagenet. """ filename = os.path.join(self._data_path, 'Annotations', self._image_set, index + '.xml') # print 'Loading: {}'.format(filename) def get_data_from_tag(node, tag): return node.getElementsByTagName(tag)[0].childNodes[0].data with open(filename) as f: data = minidom.parseString(f.read()) objs = data.getElementsByTagName('object') num_objs = len(objs) boxes = np.zeros((num_objs, 4), dtype=np.uint16) gt_classes = np.zeros((num_objs), dtype=np.int32) overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32) # Load object bounding boxes into a data frame. for ix, obj in enumerate(objs): x1 = float(get_data_from_tag(obj, 'xmin')) y1 = float(get_data_from_tag(obj, 'ymin')) x2 = float(get_data_from_tag(obj, 'xmax')) y2 = float(get_data_from_tag(obj, 'ymax')) cls = self._wnid_to_ind[ str(get_data_from_tag(obj, "name")).lower().strip()] boxes[ix, :] = [x1, y1, x2, y2] gt_classes[ix] = cls overlaps[ix, cls] = 1.0 overlaps = scipy.sparse.csr_matrix(overlaps) return {'boxes' : boxes, 'gt_classes': gt_classes, 'gt_overlaps' : overlaps, 'flipped' : False}
Example #10
Source File: imagenet.py From dafrcnn-pytorch with MIT License | 5 votes |
def _load_imagenet_annotation(self, index): """ Load image and bounding boxes info from txt files of imagenet. """ filename = os.path.join(self._data_path, 'Annotations', self._image_set, index + '.xml') # print 'Loading: {}'.format(filename) def get_data_from_tag(node, tag): return node.getElementsByTagName(tag)[0].childNodes[0].data with open(filename) as f: data = minidom.parseString(f.read()) objs = data.getElementsByTagName('object') num_objs = len(objs) boxes = np.zeros((num_objs, 4), dtype=np.uint16) gt_classes = np.zeros((num_objs), dtype=np.int32) overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32) # Load object bounding boxes into a data frame. for ix, obj in enumerate(objs): x1 = float(get_data_from_tag(obj, 'xmin')) y1 = float(get_data_from_tag(obj, 'ymin')) x2 = float(get_data_from_tag(obj, 'xmax')) y2 = float(get_data_from_tag(obj, 'ymax')) cls = self._wnid_to_ind[ str(get_data_from_tag(obj, "name")).lower().strip()] boxes[ix, :] = [x1, y1, x2, y2] gt_classes[ix] = cls overlaps[ix, cls] = 1.0 overlaps = scipy.sparse.csr_matrix(overlaps) return {'boxes' : boxes, 'gt_classes': gt_classes, 'gt_overlaps' : overlaps, 'flipped' : False}
Example #11
Source File: imagenet.py From dafrcnn-pytorch with MIT License | 5 votes |
def _load_imagenet_annotation(self, index): """ Load image and bounding boxes info from txt files of imagenet. """ filename = os.path.join(self._data_path, 'Annotations', self._image_set, index + '.xml') # print 'Loading: {}'.format(filename) def get_data_from_tag(node, tag): return node.getElementsByTagName(tag)[0].childNodes[0].data with open(filename) as f: data = minidom.parseString(f.read()) objs = data.getElementsByTagName('object') num_objs = len(objs) boxes = np.zeros((num_objs, 4), dtype=np.uint16) gt_classes = np.zeros((num_objs), dtype=np.int32) overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32) # Load object bounding boxes into a data frame. for ix, obj in enumerate(objs): x1 = float(get_data_from_tag(obj, 'xmin')) y1 = float(get_data_from_tag(obj, 'ymin')) x2 = float(get_data_from_tag(obj, 'xmax')) y2 = float(get_data_from_tag(obj, 'ymax')) cls = self._wnid_to_ind[ str(get_data_from_tag(obj, "name")).lower().strip()] boxes[ix, :] = [x1, y1, x2, y2] gt_classes[ix] = cls overlaps[ix, cls] = 1.0 overlaps = scipy.sparse.csr_matrix(overlaps) return {'boxes' : boxes, 'gt_classes': gt_classes, 'gt_overlaps' : overlaps, 'flipped' : False}
Example #12
Source File: imagenet.py From DetNet_pytorch with MIT License | 5 votes |
def _load_imagenet_annotation(self, index): """ Load image and bounding boxes info from txt files of imagenet. """ filename = os.path.join(self._data_path, 'Annotations', self._image_set, index + '.xml') # print 'Loading: {}'.format(filename) def get_data_from_tag(node, tag): return node.getElementsByTagName(tag)[0].childNodes[0].data with open(filename) as f: data = minidom.parseString(f.read()) objs = data.getElementsByTagName('object') num_objs = len(objs) boxes = np.zeros((num_objs, 4), dtype=np.uint16) gt_classes = np.zeros((num_objs), dtype=np.int32) overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32) # Load object bounding boxes into a data frame. for ix, obj in enumerate(objs): x1 = float(get_data_from_tag(obj, 'xmin')) y1 = float(get_data_from_tag(obj, 'ymin')) x2 = float(get_data_from_tag(obj, 'xmax')) y2 = float(get_data_from_tag(obj, 'ymax')) cls = self._wnid_to_ind[ str(get_data_from_tag(obj, "name")).lower().strip()] boxes[ix, :] = [x1, y1, x2, y2] gt_classes[ix] = cls overlaps[ix, cls] = 1.0 overlaps = scipy.sparse.csr_matrix(overlaps) return {'boxes' : boxes, 'gt_classes': gt_classes, 'gt_overlaps' : overlaps, 'flipped' : False}