generate_missing_data.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:Generative-ConvACs 作者: HUJI-Deep 项目源码 文件源码
def convert_dataset(args):
    try:
        if args.min_rects > args.max_rects:
            raise ValueError('min_rect must be less than or equal to max_rect.')
        if args.min_width > args.max_width:
            raise ValueError('min_width must be less than or equal to max_width.')
        try:
            os.makedirs(args.output_dir)
        except OSError as exc:  # Python >2.5
            if exc.errno == errno.EEXIST and os.path.isdir(args.output_dir):
                pass
            else:
                raise ValueError('output_dir argument is not a valid path.')
        total_images = len(args.filenames)
        params = zip(args.filenames, [args] * total_images)
        pool = Pool(initializer=init_worker)
        pbar = progressbar.ProgressBar(widgets=[progressbar.FormatLabel('\rProcessed %(value)d of %(max)d Images '), progressbar.Bar()], maxval=total_images, term_width=50).start()
        try:
            results = pool.imap_unordered(corrupt_source_image, params, chunksize=max(int(math.sqrt(len(args.filenames)))/2, 10))
            for i in range(len(args.filenames)):
                next(results)
                pbar.update(i+1)
            pool.close()
            pool.join()
            pbar.finish()
        except KeyboardInterrupt:
            pool.terminate()
            pool.join()
            pbar.finish()
            raise
    except ValueError as e:
        print
        print 'Bad parameters:', e
        raise e
    except KeyboardInterrupt:
        print
        if __name__ == '__main__':
            print 'User stopped generation!'
        raise 
    except:
        print
        print "Unexpected error:", sys.exc_info()[0]
        raise
# Main routine
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号