Python os.path.isdir() Examples

The following are code examples for showing how to use os.path.isdir(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: rpm2swidtag   Author: swidtags   File: swidtags.py    Apache License 2.0 6 votes vote down vote up
def purge_generated_dir(self):
		if not path.isdir(self.dir_generated):
			return
		count = 0
		for f in listdir(self.dir_generated):
			try:
				unlink(path.join(self.dir_generated, f))
				count += 1
			except OSError as e:
				logger.warning("Failed to remove [%s]: %s", f, e)
		try:
			rmdir(self.dir_generated)
		except OSError:
			logger.warning("Failed to remove [%s]: %s", self.dir_generated, e)
		if count > 0:
			logger.debug("Removed %d generated files from %s", count, self.dir_generated) 
Example 2
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: test_data_datasets.py    Apache License 2.0 6 votes vote down vote up
def test_pascal_voc_detection():
    if not osp.isdir(osp.expanduser('~/.mxnet/datasets/voc')):
        return

    train = data.VOCDetection(splits=((2007, 'trainval'), (2012, 'trainval')))
    name = str(train)
    val = data.VOCDetection(splits=((2007, 'test'), ))
    name = str(val)

    assert train.classes == val.classes

    for _ in range(10):
        index = np.random.randint(0, len(train))
        _ = train[index]

    for _ in range(10):
        index = np.random.randint(0, len(val))
        _ = val[index] 
Example 3
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: market1501.py    Apache License 2.0 6 votes vote down vote up
def main():
    name = "Market-1501-v15.09.15"
    url = "http://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/"+name+".zip"
    root = osp.expanduser("~/.mxnet/datasets")
    if not os.path.exists(root):
        os.mkdir(root)
    fpath = osp.join(root, name+'.zip')
    exdir = osp.join(root, name)

    if os.path.exists(fpath):
        if not osp.isdir(exdir):
            extract(fpath)
            make_list(exdir)
            
    else:
        download(url, fpath, False)
        extract(fpath)
        make_list(exdir) 
Example 4
Project: Manga-colorization---cycle-gan   Author: OValery16   File: get_data.py    Mozilla Public License 2.0 6 votes vote down vote up
def _download_data(self, dataset_url, save_path):
        if not isdir(save_path):
            os.makedirs(save_path)

        base = basename(dataset_url)
        temp_save_path = join(save_path, base)

        with open(temp_save_path, "wb") as f:
            r = requests.get(dataset_url)
            f.write(r.content)

        if base.endswith('.tar.gz'):
            obj = tarfile.open(temp_save_path)
        elif base.endswith('.zip'):
            obj = ZipFile(temp_save_path, 'r')
        else:
            raise ValueError("Unknown File Type: {0}.".format(base))

        self._print("Unpacking Data...")
        obj.extractall(save_path)
        obj.close()
        os.remove(temp_save_path) 
Example 5
Project: calmjs   Author: calmjs   File: toolchain.py    GNU General Public License v2.0 6 votes vote down vote up
def compile_bundle_entry(self, spec, entry):
        """
        Handler for each entry for the bundle method of the compile
        process.  This copies the source file or directory into the
        build directory.
        """

        modname, source, target, modpath = entry
        bundled_modpath = {modname: modpath}
        bundled_target = {modname: target}
        export_module_name = []
        if isfile(source):
            export_module_name.append(modname)
            copy_target = join(spec[BUILD_DIR], target)
            if not exists(dirname(copy_target)):
                makedirs(dirname(copy_target))
            shutil.copy(source, copy_target)
        elif isdir(source):
            copy_target = join(spec[BUILD_DIR], modname)
            shutil.copytree(source, copy_target)

        return bundled_modpath, bundled_target, export_module_name 
Example 6
Project: DataHack2018   Author: InnovizTech   File: iou_evaluator.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def evaluate_dataset(top_folder_gt, top_folder_pred, validmode=False):
    # find all folders in top_folder_gt
    folders = [e for e in os.listdir(top_folder_gt) if osp.isdir(osp.join(top_folder_gt, e))]
    if len(folders) == 0:
        raise ValueError("No folders inside ground truth folder {}".format(top_folder_gt))

    if validmode:
        # keep only folders that have matches in predictions folder
        folders = [folder for folder in folders if osp.isdir(osp.join(top_folder_pred, folder))]
    else:
        # verify all folders in gt have corresponding folders in top_folder_pred
        for folder in folders:
            if not osp.isdir(osp.join(top_folder_pred, folder)):
                raise ValueError("No matching prediction folder for {}".format(folder))

    agg_tp = 0
    agg_fp = 0
    agg_fn = 0
    # evaluate and aggregate data from all folders
    for folder in folders:
        tp, fn, fp = evaluate_folder(osp.join(top_folder_gt, folder), osp.join(top_folder_pred, folder), validmode)
        agg_tp += tp
        agg_fn += fn
        agg_fp += fp
        # calculate IoU
        if agg_tp + agg_fp + agg_fn == 0:
            iou = 1.
        else:
            iou = agg_tp / float(agg_tp + agg_fp + agg_fn)
        print("IoU: {:.2f}%".format(iou*100))

    return iou 
Example 7
Project: rpm2swidtag   Author: swidtags   File: swidtags.py    Apache License 2.0 5 votes vote down vote up
def create_generated_dir(self):
		if not path.isdir(self.dir_generated):
			makedirs(self.dir_generated) 
Example 8
Project: rpm2swidtag   Author: swidtags   File: swidtags.py    Apache License 2.0 5 votes vote down vote up
def create_download_dir(self, dirname):
		dirname = path.join(self.dir_downloaded, dirname)
		if not path.isdir(dirname):
			makedirs(dirname) 
Example 9
Project: rpm2swidtag   Author: swidtags   File: swidtags.py    Apache License 2.0 5 votes vote down vote up
def create_swidtags_d_symlink(self, basename=None):
		if basename:
			target = path.join(SWIDTAG_DIR_DOWNLOAD, basename)
		else:
			basename = self.generated_dirname
			target = path.join(SWIDTAG_DIR_GEN, basename)
		if not path.isdir(self.swidtags_d):
			makedirs(self.swidtags_d)
		src = path.join(self.swidtags_d, basename)
		if not path.islink(src):
			symlink(path.join("../../..", target), src) 
Example 10
Project: rpm2swidtag   Author: swidtags   File: repodata.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, repo):
		self.path = repo
		if not path.isdir(repo):
			raise Error("%s is not directory" % repo) from None
		self.__repomd = None 
Example 11
Project: mmdetection   Author: open-mmlab   File: pascal_voc.py    Apache License 2.0 5 votes vote down vote up
def main():
    args = parse_args()
    devkit_path = args.devkit_path
    out_dir = args.out_dir if args.out_dir else devkit_path
    mmcv.mkdir_or_exist(out_dir)

    years = []
    if osp.isdir(osp.join(devkit_path, 'VOC2007')):
        years.append('2007')
    if osp.isdir(osp.join(devkit_path, 'VOC2012')):
        years.append('2012')
    if '2007' in years and '2012' in years:
        years.append(['2007', '2012'])
    if not years:
        raise IOError('The devkit path {} contains neither "VOC2007" nor '
                      '"VOC2012" subfolder'.format(devkit_path))
    for year in years:
        if year == '2007':
            prefix = 'voc07'
        elif year == '2012':
            prefix = 'voc12'
        elif year == ['2007', '2012']:
            prefix = 'voc0712'
        for split in ['train', 'val', 'trainval']:
            dataset_name = prefix + '_' + split
            print('processing {} ...'.format(dataset_name))
            cvt_annotations(devkit_path, year, split,
                            osp.join(out_dir, dataset_name + '.pkl'))
        if not isinstance(year, list):
            dataset_name = prefix + '_test'
            print('processing {} ...'.format(dataset_name))
            cvt_annotations(devkit_path, year, 'test',
                            osp.join(out_dir, dataset_name + '.pkl'))
    print('Done!') 
Example 12
Project: programsynthesishunting   Author: flexgp   File: file_io.py    GNU General Public License v3.0 5 votes vote down vote up
def generate_folders_and_files():
    """
    Generates necessary folders and files for saving statistics and parameters.

    :return: Nothing.
    """

    if params['EXPERIMENT_NAME']:
        # Experiment manager is being used.
        path_1 = path.join(getcwd(), "..", "results")

        if not path.isdir(path_1):
            # Create results folder.
            makedirs(path_1)

        # Set file path to include experiment name.
        params['FILE_PATH'] = path.join(path_1, params['EXPERIMENT_NAME'])

    else:
        # Set file path to results folder.
        params['FILE_PATH'] = path.join(getcwd(), "..", "results")

    # Generate save folders
    if not path.isdir(params['FILE_PATH']):
        makedirs(params['FILE_PATH'])

    if not path.isdir(path.join(params['FILE_PATH'],
                                str(params['TIME_STAMP']))):
        makedirs(path.join(params['FILE_PATH'],
                        str(params['TIME_STAMP'])))

    params['FILE_PATH'] = path.join(params['FILE_PATH'],
                                    str(params['TIME_STAMP']))

    save_params_to_file() 
Example 13
Project: Ansible-Example-AB2018   Author: umit-ozturk   File: __init__.py    MIT License 5 votes vote down vote up
def metadata_isdir(name):
        """Is the named metadata a directory?  (like ``os.path.isdir()``)""" 
Example 14
Project: Ansible-Example-AB2018   Author: umit-ozturk   File: __init__.py    MIT License 5 votes vote down vote up
def resource_isdir(resource_name):
        """Is the named resource a directory?  (like ``os.path.isdir()``)""" 
Example 15
Project: Ansible-Example-AB2018   Author: umit-ozturk   File: __init__.py    MIT License 5 votes vote down vote up
def _isdir(self, path):
        return os.path.isdir(path) 
Example 16
Project: Ansible-Example-AB2018   Author: umit-ozturk   File: __init__.py    MIT License 5 votes vote down vote up
def distributions_from_metadata(path):
    root = os.path.dirname(path)
    if os.path.isdir(path):
        if len(os.listdir(path)) == 0:
            # empty metadata dir; skip
            return
        metadata = PathMetadata(root, path)
    else:
        metadata = FileMetadata(path)
    entry = os.path.basename(path)
    yield Distribution.from_location(
        root, entry, metadata, precedence=DEVELOP_DIST,
    ) 
Example 17
Project: Ansible-Example-AB2018   Author: umit-ozturk   File: __init__.py    MIT License 5 votes vote down vote up
def _bypass_ensure_directory(path):
    """Sandbox-bypassing version of ensure_directory()"""
    if not WRITE_SUPPORT:
        raise IOError('"os.mkdir" not supported on this platform.')
    dirname, filename = split(path)
    if dirname and filename and not isdir(dirname):
        _bypass_ensure_directory(dirname)
        mkdir(dirname, 0o755) 
Example 18
Project: Ansible-Example-AB2018   Author: umit-ozturk   File: __init__.py    MIT License 5 votes vote down vote up
def resource_isdir(resource_name):
        """Is the named resource a directory?  (like ``os.path.isdir()``)""" 
Example 19
Project: Ansible-Example-AB2018   Author: umit-ozturk   File: __init__.py    MIT License 5 votes vote down vote up
def _isdir(self, path):
        return os.path.isdir(path) 
Example 20
Project: Ansible-Example-AB2018   Author: umit-ozturk   File: __init__.py    MIT License 5 votes vote down vote up
def distributions_from_metadata(path):
    root = os.path.dirname(path)
    if os.path.isdir(path):
        if len(os.listdir(path)) == 0:
            # empty metadata dir; skip
            return
        metadata = PathMetadata(root, path)
    else:
        metadata = FileMetadata(path)
    entry = os.path.basename(path)
    yield Distribution.from_location(
        root, entry, metadata, precedence=DEVELOP_DIST,
    ) 
Example 21
Project: Ansible-Example-AB2018   Author: umit-ozturk   File: __init__.py    MIT License 5 votes vote down vote up
def _bypass_ensure_directory(path):
    """Sandbox-bypassing version of ensure_directory()"""
    if not WRITE_SUPPORT:
        raise IOError('"os.mkdir" not supported on this platform.')
    dirname, filename = split(path)
    if dirname and filename and not isdir(dirname):
        _bypass_ensure_directory(dirname)
        mkdir(dirname, 0o755) 
Example 22
Project: subfont   Author: minacle   File: subfont.py    MIT License 5 votes vote down vote up
def flatpaths(paths):
    r = paths[:]
    for item in r:
        if isdir(item):
            files_to_add = []
            for _, _, files in walk(item):
                files_to_add.append(files)
            r.extend(files_to_add)
    return r 
Example 23
Project: google_streetview   Author: rrwen   File: api.py    MIT License 5 votes vote down vote up
def download_links(self, dir_path, metadata_file='metadata.json', metadata_status='status', status_ok='OK'):
    """Download Google Street View images from parameter queries if they are available.
    
    Args:
      dir_path (str):
        Path of directory to save downloads of images from :class:`api.results`.links
      metadata_file (str):
         Name of the file with extension to save the :class:`api.results`.metadata
      metadata_status (str):
        Key name of the status value from :class:`api.results`.metadata response from the metadata API request.
      status_ok (str):
        Value from the metadata API response status indicating that an image is available.
    """
    metadata = self.metadata
    if not path.isdir(dir_path):
      makedirs(dir_path)
    
    # (download) Download images if status from metadata is ok
    for i, url in enumerate(self.links):
      if metadata[i][metadata_status] == status_ok:
        file_path = path.join(dir_path, 'gsv_' + str(i) + '.jpg')
        metadata[i]['_file'] = path.basename(file_path) # add file reference
        helpers.download(url, file_path)
    
    # (metadata) Save metadata with file reference
    metadata_path = path.join(dir_path, metadata_file)
    with open(metadata_path, 'w') as out_file:
      json.dump(metadata, out_file) 
Example 24
Project: google_streetview   Author: rrwen   File: test_api_results.py    MIT License 5 votes vote down vote up
def tearDown(self):
    if isfile(self.tempfile):
      remove(self.tempfile)
    if isdir(self.tempdir):
      rmtree(self.tempdir) 
Example 25
Project: google_streetview   Author: rrwen   File: test_cli.py    MIT License 5 votes vote down vote up
def tearDown(self):
    if isfile(self.tempfile):
      remove(self.tempfile)
    if isdir(self.tempdir):
      rmtree(self.tempdir) 
Example 26
Project: flasky   Author: RoseOu   File: pkg_resources.py    MIT License 5 votes vote down vote up
def _bypass_ensure_directory(name, mode=0x1FF):  # 0777
    # Sandbox-bypassing version of ensure_directory()
    if not WRITE_SUPPORT:
        raise IOError('"os.mkdir" not supported on this platform.')
    dirname, filename = split(name)
    if dirname and filename and not isdir(dirname):
        _bypass_ensure_directory(dirname)
        mkdir(dirname, mode) 
Example 27
Project: flasky   Author: RoseOu   File: pkg_resources.py    MIT License 5 votes vote down vote up
def metadata_isdir(name):
        """Is the named metadata a directory?  (like ``os.path.isdir()``)""" 
Example 28
Project: flasky   Author: RoseOu   File: pkg_resources.py    MIT License 5 votes vote down vote up
def resource_isdir(resource_name):
        """Is the named resource a directory?  (like ``os.path.isdir()``)""" 
Example 29
Project: flasky   Author: RoseOu   File: pkg_resources.py    MIT License 5 votes vote down vote up
def _isdir(self,path):
        return os.path.isdir(path) 
Example 30
Project: flasky   Author: RoseOu   File: pkg_resources.py    MIT License 5 votes vote down vote up
def find_on_path(importer, path_item, only=False):
    """Yield distributions accessible on a sys.path directory"""
    path_item = _normalize_cached(path_item)

    if os.path.isdir(path_item) and os.access(path_item, os.R_OK):
        if path_item.lower().endswith('.egg'):
            # unpacked egg
            yield Distribution.from_filename(
                path_item, metadata=PathMetadata(
                    path_item, os.path.join(path_item,'EGG-INFO')
                )
            )
        else:
            # scan for .egg and .egg-info in directory
            for entry in os.listdir(path_item):
                lower = entry.lower()
                if lower.endswith('.egg-info') or lower.endswith('.dist-info'):
                    fullpath = os.path.join(path_item, entry)
                    if os.path.isdir(fullpath):
                        # egg-info directory, allow getting metadata
                        metadata = PathMetadata(path_item, fullpath)
                    else:
                        metadata = FileMetadata(fullpath)
                    yield Distribution.from_location(
                        path_item,entry,metadata,precedence=DEVELOP_DIST
                    )
                elif not only and lower.endswith('.egg'):
                    for dist in find_distributions(os.path.join(path_item, entry)):
                        yield dist
                elif not only and lower.endswith('.egg-link'):
                    entry_file = open(os.path.join(path_item, entry))
                    try:
                        entry_lines = entry_file.readlines()
                    finally:
                        entry_file.close()
                    for line in entry_lines:
                        if not line.strip(): continue
                        for item in find_distributions(os.path.join(path_item,line.rstrip())):
                            yield item
                        break 
Example 31
Project: flasky   Author: RoseOu   File: pkg_resources.py    MIT License 5 votes vote down vote up
def _bypass_ensure_directory(name, mode=0x1FF):  # 0777
    # Sandbox-bypassing version of ensure_directory()
    if not WRITE_SUPPORT:
        raise IOError('"os.mkdir" not supported on this platform.')
    dirname, filename = split(name)
    if dirname and filename and not isdir(dirname):
        _bypass_ensure_directory(dirname)
        mkdir(dirname, mode) 
Example 32
Project: flasky   Author: RoseOu   File: pkg_resources.py    MIT License 5 votes vote down vote up
def metadata_isdir(name):
        """Is the named metadata a directory?  (like ``os.path.isdir()``)""" 
Example 33
Project: flasky   Author: RoseOu   File: pkg_resources.py    MIT License 5 votes vote down vote up
def resource_isdir(resource_name):
        """Is the named resource a directory?  (like ``os.path.isdir()``)""" 
Example 34
Project: flasky   Author: RoseOu   File: pkg_resources.py    MIT License 5 votes vote down vote up
def _isdir(self,path):
        return os.path.isdir(path) 
Example 35
Project: flasky   Author: RoseOu   File: pkg_resources.py    MIT License 5 votes vote down vote up
def find_on_path(importer, path_item, only=False):
    """Yield distributions accessible on a sys.path directory"""
    path_item = _normalize_cached(path_item)

    if os.path.isdir(path_item) and os.access(path_item, os.R_OK):
        if path_item.lower().endswith('.egg'):
            # unpacked egg
            yield Distribution.from_filename(
                path_item, metadata=PathMetadata(
                    path_item, os.path.join(path_item,'EGG-INFO')
                )
            )
        else:
            # scan for .egg and .egg-info in directory
            for entry in os.listdir(path_item):
                lower = entry.lower()
                if lower.endswith('.egg-info') or lower.endswith('.dist-info'):
                    fullpath = os.path.join(path_item, entry)
                    if os.path.isdir(fullpath):
                        # egg-info directory, allow getting metadata
                        metadata = PathMetadata(path_item, fullpath)
                    else:
                        metadata = FileMetadata(fullpath)
                    yield Distribution.from_location(
                        path_item,entry,metadata,precedence=DEVELOP_DIST
                    )
                elif not only and lower.endswith('.egg'):
                    for dist in find_distributions(os.path.join(path_item, entry)):
                        yield dist
                elif not only and lower.endswith('.egg-link'):
                    entry_file = open(os.path.join(path_item, entry))
                    try:
                        entry_lines = entry_file.readlines()
                    finally:
                        entry_file.close()
                    for line in entry_lines:
                        if not line.strip(): continue
                        for item in find_distributions(os.path.join(path_item,line.rstrip())):
                            yield item
                        break 
Example 36
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: test_data_datasets.py    Apache License 2.0 5 votes vote down vote up
def test_coco_detection():
    if not osp.isdir(osp.expanduser('~/.mxnet/datasets/coco')):
        return

    # use valid only, loading training split is very slow
    val = data.COCODetection(splits=('instances_val2017'))
    name = str(val)
    assert len(val.classes) > 0

    for _ in range(10):
        index = np.random.randint(0, len(val))
        _ = val[index] 
Example 37
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: test_data_datasets.py    Apache License 2.0 5 votes vote down vote up
def test_coco_instance():
    if not osp.isdir(osp.expanduser('~/.mxnet/datasets/coco')):
        return

    # use valid only, loading training split is very slow
    val = data.COCOInstance(splits=('instances_val2017',))
    name = str(val)
    assert len(val.classes) > 0

    for _ in range(10):
        index = np.random.randint(0, len(val))
        _ = val[index] 
Example 38
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: test_data_datasets.py    Apache License 2.0 5 votes vote down vote up
def test_voc_segmentation():
    if not osp.isdir(osp.expanduser('~/.mxnet/datasets/voc')):
        return

    # use valid only, loading training split is very slow
    val = data.VOCSegmentation(split='train')
    name = str(val)
    assert len(val.classes) > 0

    for _ in range(10):
        index = np.random.randint(0, len(val))
        _ = val[index] 
Example 39
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: test_data_datasets.py    Apache License 2.0 5 votes vote down vote up
def test_voc_aug_segmentation():
    if not osp.isdir(osp.expanduser('~/.mxnet/datasets/voc')):
        return

    # use valid only, loading training split is very slow
    val = data.VOCAugSegmentation(split='train')
    name = str(val)
    assert len(val.classes) > 0

    for _ in range(10):
        index = np.random.randint(0, len(val))
        _ = val[index] 
Example 40
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: test_data_datasets.py    Apache License 2.0 5 votes vote down vote up
def test_citys_segmentation():
    if not osp.isdir(osp.expanduser('~/.mxnet/datasets/ade')):
        return

    # use valid only, loading training split is very slow
    val = data.CitySegmentation(split='train')
    name = str(val)

    for _ in range(10):
        index = np.random.randint(0, len(val))
        _ = val[index] 
Example 41
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: test_data_transforms.py    Apache License 2.0 5 votes vote down vote up
def test_transforms_presets_ssd():
    im_fname = gcv.utils.download('https://github.com/dmlc/web-data/blob/master/' +
                                  'gluoncv/detection/biking.jpg?raw=true', path='biking.jpg')
    x, orig_img = ssd.load_test(im_fname, short=512)
    x1, orig_img1 = ssd.transform_test(mx.image.imread(im_fname), short=512)
    np.testing.assert_allclose(x.asnumpy(), x1.asnumpy())
    np.testing.assert_allclose(orig_img, orig_img1)
    if not osp.isdir(osp.expanduser('~/.mxnet/datasets/voc')):
        return
    train_dataset = gcv.data.VOCDetection(splits=((2007, 'trainval'), (2012, 'trainval')))
    val_dataset = gcv.data.VOCDetection(splits=[(2007, 'test')])
    width, height = (512, 512)
    net = gcv.model_zoo.get_model('ssd_512_resnet50_v1_voc', pretrained=False, pretrained_base=False)
    net.initialize()
    num_workers = 0
    batch_size = 4
    with autograd.train_mode():
        _, _, anchors = net(mx.nd.zeros((1, 3, height, width)))
    batchify_fn = Tuple(Stack(), Stack(), Stack())  # stack image, cls_targets, box_targets
    train_loader = gluon.data.DataLoader(
        train_dataset.transform(ssd.SSDDefaultTrainTransform(width, height, anchors)),
        batch_size, True, batchify_fn=batchify_fn, last_batch='rollover', num_workers=num_workers)
    val_batchify_fn = Tuple(Stack(), Pad(pad_val=-1))
    val_loader = gluon.data.DataLoader(
        val_dataset.transform(ssd.SSDDefaultValTransform(width, height)),
        batch_size, False, batchify_fn=val_batchify_fn, last_batch='keep', num_workers=num_workers)
    train_loader2 = gluon.data.DataLoader(
        train_dataset.transform(ssd.SSDDefaultTrainTransform(width, height)),
        batch_size, True, batchify_fn=val_batchify_fn, last_batch='rollover', num_workers=num_workers)

    for loader in [train_loader, val_loader, train_loader2]:
        for i, batch in enumerate(loader):
            if i > 1:
                break
            pass 
Example 42
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: test_data_transforms.py    Apache License 2.0 5 votes vote down vote up
def test_transforms_presets_rcnn():
    im_fname = gcv.utils.download('https://github.com/dmlc/web-data/blob/master/' +
                                  'gluoncv/detection/biking.jpg?raw=true', path='biking.jpg')
    x, orig_img = rcnn.load_test(im_fname, short=600, max_size=1000)
    x1, orig_img1 = rcnn.transform_test(mx.image.imread(im_fname), short=600, max_size=1000)
    np.testing.assert_allclose(x.asnumpy(), x1.asnumpy())
    np.testing.assert_allclose(orig_img, orig_img1)
    if not osp.isdir(osp.expanduser('~/.mxnet/datasets/voc')):
        return
    train_dataset = gcv.data.VOCDetection(splits=((2007, 'trainval'), (2012, 'trainval')))
    val_dataset = gcv.data.VOCDetection(splits=[(2007, 'test')])
    width, height = (512, 512)
    net = gcv.model_zoo.get_model('faster_rcnn_resnet50_v1b_voc', pretrained=False, pretrained_base=False)
    net.initialize()
    num_workers = 0
    short, max_size = 600, 1000
    batch_size = 4
    train_bfn = batchify.Tuple(*[batchify.Append() for _ in range(5)])
    train_loader = mx.gluon.data.DataLoader(
        train_dataset.transform(rcnn.FasterRCNNDefaultTrainTransform(short, max_size, net, flip_p=0.5)),
        batch_size, True, batchify_fn=train_bfn, last_batch='rollover', num_workers=num_workers)
    val_bfn = batchify.Tuple(*[batchify.Append() for _ in range(3)])
    val_loader = mx.gluon.data.DataLoader(
        val_dataset.transform(rcnn.FasterRCNNDefaultValTransform(short, max_size)),
        batch_size, False, batchify_fn=val_bfn, last_batch='keep', num_workers=num_workers)
    train_loader2 = gluon.data.DataLoader(
        train_dataset.transform(rcnn.FasterRCNNDefaultTrainTransform(short, max_size)),
        batch_size, True, batchify_fn=batchify.Tuple(*[batchify.Append() for _ in range(2)]),
        last_batch='rollover', num_workers=num_workers)

    for loader in [train_loader, val_loader, train_loader2]:
        for i, batch in enumerate(loader):
            if i > 1:
                break
            pass 
Example 43
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: test_data_transforms.py    Apache License 2.0 5 votes vote down vote up
def test_transforms_presets_yolo():
    im_fname = gcv.utils.download('https://github.com/dmlc/web-data/blob/master/' +
                                  'gluoncv/detection/biking.jpg?raw=true', path='biking.jpg')
    x, orig_img = yolo.load_test(im_fname, short=512)
    x1, orig_img1 = yolo.transform_test(mx.image.imread(im_fname), short=512)
    np.testing.assert_allclose(x.asnumpy(), x1.asnumpy())
    np.testing.assert_allclose(orig_img, orig_img1)
    if not osp.isdir(osp.expanduser('~/.mxnet/datasets/voc')):
        return
    train_dataset = gcv.data.VOCDetection(splits=((2007, 'trainval'), (2012, 'trainval')))
    val_dataset = gcv.data.VOCDetection(splits=[(2007, 'test')])
    width, height = (512, 512)
    net = gcv.model_zoo.get_model('yolo3_darknet53_voc', pretrained=False, pretrained_base=False)
    net.initialize()
    num_workers = 0
    batch_size = 4
    batchify_fn = Tuple(*([Stack() for _ in range(6)] + [Pad(axis=0, pad_val=-1) for _ in range(1)]))
    train_loader = gluon.data.DataLoader(
        train_dataset.transform(yolo.YOLO3DefaultTrainTransform(width, height, net)),
        batch_size, True, batchify_fn=batchify_fn, last_batch='rollover', num_workers=num_workers)
    val_batchify_fn = Tuple(Stack(), Pad(pad_val=-1))
    val_loader = gluon.data.DataLoader(
        val_dataset.transform(yolo.YOLO3DefaultValTransform(width, height)),
        batch_size, False, batchify_fn=val_batchify_fn, last_batch='keep', num_workers=num_workers)
    train_loader2 = gluon.data.DataLoader(
        train_dataset.transform(yolo.YOLO3DefaultTrainTransform(width, height)),
        batch_size, True, batchify_fn=val_batchify_fn, last_batch='rollover', num_workers=num_workers)

    for loader in [train_loader, val_loader, train_loader2]:
        for i, batch in enumerate(loader):
            if i > 1:
                break
            pass 
Example 44
Project: sic   Author: Yanixos   File: __init__.py    GNU General Public License v3.0 5 votes vote down vote up
def metadata_isdir(name):
        """Is the named metadata a directory?  (like ``os.path.isdir()``)""" 
Example 45
Project: sic   Author: Yanixos   File: __init__.py    GNU General Public License v3.0 5 votes vote down vote up
def resource_isdir(resource_name):
        """Is the named resource a directory?  (like ``os.path.isdir()``)""" 
Example 46
Project: sic   Author: Yanixos   File: __init__.py    GNU General Public License v3.0 5 votes vote down vote up
def _isdir(self, path):
        return os.path.isdir(path) 
Example 47
Project: sic   Author: Yanixos   File: __init__.py    GNU General Public License v3.0 5 votes vote down vote up
def ensure_directory(path):
    """Ensure that the parent directory of `path` exists"""
    dirname = os.path.dirname(path)
    if not os.path.isdir(dirname):
        os.makedirs(dirname) 
Example 48
Project: sic   Author: Yanixos   File: __init__.py    GNU General Public License v3.0 5 votes vote down vote up
def metadata_isdir(name):
        """Is the named metadata a directory?  (like ``os.path.isdir()``)""" 
Example 49
Project: sic   Author: Yanixos   File: __init__.py    GNU General Public License v3.0 5 votes vote down vote up
def resource_isdir(resource_name):
        """Is the named resource a directory?  (like ``os.path.isdir()``)""" 
Example 50
Project: sic   Author: Yanixos   File: __init__.py    GNU General Public License v3.0 5 votes vote down vote up
def _isdir(self, path):
        return os.path.isdir(path)