Python chainer 模块,set_debug() 实例源码

我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用chainer.set_debug()

项目:chainer-faster-rcnn    作者:mitmul    | 项目源码 | 文件源码
def setUp(self):
        chainer.set_debug(True)
        np.random.seed(0)
        x = np.random.randint(0, 255, size=(224, 224, 3)).astype(np.float)
        x -= np.array([[[102.9801, 115.9465, 122.7717]]])
        self.x = np.expand_dims(x, 0).transpose(0, 3, 1, 2).astype(np.float32)
        self.im_info = np.array([[224, 224, 1.6]])
        self.gt_boxes = np.array([
            [10, 10, 60, 200, 0],
            [50, 100, 210, 210, 1],
            [160, 40, 200, 70, 2]
        ])
项目:chainer-segnet    作者:pfnet-research    | 项目源码 | 文件源码
def setUp(self):
        self.x = numpy.random.uniform(-1, 1, (2, 2)).astype(numpy.float32)
        # `0` is required to avoid NaN
        self.t = numpy.array([self.t_value, 0], dtype=numpy.int32)
        self.original_debug = chainer.is_debug()
        chainer.set_debug(True)
项目:chainer-segnet    作者:pfnet-research    | 项目源码 | 文件源码
def tearDown(self):
        chainer.set_debug(self.original_debug)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def setUp(self):
        self.link = links.EmbedID(2, 2)
        self.t = numpy.array([self.t_value], dtype=numpy.int32)
        self.original_debug = chainer.is_debug()
        chainer.set_debug(True)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def tearDown(self):
        chainer.set_debug(self.original_debug)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def setUp(self):
        self.original_debug = chainer.is_debug()
        chainer.set_debug(True)
        self.one = numpy.array([1], numpy.float32)
        self.f = chainer.Function()
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def tearDown(self):
        chainer.set_debug(self.original_debug)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def setUp(self):
        self.original_debug = chainer.is_debug()
        chainer.set_debug(True)
        self.one = numpy.array([1], numpy.float32)
        self.f = chainer.Function()
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def setUp(self):
        self.x = numpy.random.uniform(-1, 1, (2, 2)).astype(numpy.float32)
        # `0` is required to avoid NaN
        self.t = numpy.array([self.t_value, 0], dtype=numpy.int32)
        self.original_debug = chainer.is_debug()
        chainer.set_debug(True)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def tearDown(self):
        chainer.set_debug(self.original_debug)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def setUp(self):
        self.x = numpy.random.uniform(-1, 1, (1, 2)).astype(numpy.float32)
        self.t = numpy.array([self.t_value], dtype=numpy.int32)
        self.original_debug = chainer.is_debug()
        chainer.set_debug(True)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def tearDown(self):
        chainer.set_debug(self.original_debug)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def setUp(self):
        self.x = np.array([1], np.float32)
        chainer.set_debug(True)
项目:nmtrain    作者:philip30    | 项目源码 | 文件源码
def setUp(self):
    self.x = numpy.random.uniform(-1, 1, (2, 2)).astype(numpy.float32)
    # `0` is required to avoid NaN
    self.t = numpy.array([self.t_value, 0], dtype=numpy.int32)
    self.original_debug = chainer.is_debug()
    chainer.set_debug(True)
项目:nmtrain    作者:philip30    | 项目源码 | 文件源码
def tearDown(self):
    chainer.set_debug(self.original_debug)
项目:fontkaruta_classifier    作者:suga93    | 项目源码 | 文件源码
def main():

    import random

    # Model class options
    model_parser = argparse.ArgumentParser(description='Model Parameters', add_help=False)
    model_parser.add_argument('--model_name', type=str, help='Model name {"SimpleCNN", "MiddleCNN"}')
    model_parser.add_argument('--init_model', type=str, help='Initialize the model from given file')
    model_parser.add_argument('--n_classes', type=int, default=48, help='Number of classes')
    model_args, remaining_argv = model_parser.parse_known_args()

    # Model runtime options
    runtime_parser = argparse.ArgumentParser(description='Runtime Parameters', add_help=False)
    runtime_parser.add_argument('--gpu', type=int, help='GPU ID (negative value indicates CPU')
    runtime_parser.add_argument('--test_dir', type=str, help='/path/to/test_dir')
    runtime_parser.add_argument('--nb_output', type=int, default=10, help='Number of output images')
    runtime_parser.add_argument('--save_dir', type=str, default='./grad_cam', help='Save directory')
    runtime_args, remaining_argv = runtime_parser.parse_known_args(remaining_argv)

    # merge options
    parser = argparse.ArgumentParser(
        description='Visualize Saliency',
        parents=[model_parser, runtime_parser])
    parser.add_argument('--debug', action='store_true', help='if specified, using chainer.set_debug()')
    args = parser.parse_args()

    chainer.set_debug(args.debug)
    assert model_args.init_model is not None, "init_model must be specified."

    # load model
    grad_cam = build_gradcam_model(args.n_classes, args.model_name, args.init_model, args.gpu)


    ''' Visualization '''
    for idx in range(len(fonts_dict)):
        target_dir = os.path.join(args.test_dir, fonts_dict[idx])
        if not os.path.isdir(target_dir):
            continue
        filenames = sorted(os.listdir(target_dir))
        si = list(range(len(filenames)))
        random.shuffle(si)

        for j in range(args.nb_output):
            filename = filenames[si[j]]
            img = imread(os.path.join(target_dir, filename), mode='RGB').astype(np.float32)
            arr = convert_to_array(img, args.gpu)
            mask, pred_idx = grad_cam(arr, None)
            if idx == pred_idx:
                save_dir = os.path.join(args.save_dir, fonts_dict[idx])
                if not os.path.isdir(save_dir):
                    os.makedirs(save_dir)

                save_cam_image(img, mask, os.path.join(save_dir, filename))
            else:
                print("true :", fonts_dict[idx], "!= predict :", fonts_dict[pred_idx])
项目:fontkaruta_classifier    作者:suga93    | 项目源码 | 文件源码
def main():

    # Model class options
    model_parser = argparse.ArgumentParser(description='Model Parameters', add_help=False)
    model_parser.add_argument('--model_name', type=str, help='Model name {"SimpleCNN", "MiddleCNN"}')
    model_parser.add_argument('--init_model', type=str, help='Initialize the model from given file')
    model_parser.add_argument('--n_classes', type=int, default=48, help='Number of classes')
    model_args, remaining_argv = model_parser.parse_known_args()

    # Model runtime options
    runtime_parser = argparse.ArgumentParser(description='Runtime Parameters', add_help=False)
    runtime_parser.add_argument('--gpu', type=int, default=-1, help='GPU ID (negative value indicates CPU')
    runtime_parser.add_argument('--input_image', type=str, help='/path/to/input_image.jpg')
    runtime_parser.add_argument('--target_label', type=str, help='If not specified, predicted label is used as target.')    
    runtime_parser.add_argument('--save_dir', type=str, default='./grad_cam', help='Save directory')
    runtime_args, remaining_argv = runtime_parser.parse_known_args(remaining_argv)

    # merge options
    parser = argparse.ArgumentParser(
        description='Visualize Saliency',
        parents=[model_parser, runtime_parser])
    parser.add_argument('--debug', action='store_true', help='if specified, using chainer.set_debug()')
    args = parser.parse_args()

    chainer.set_debug(args.debug)
    assert runtime_args.input_image is not None, "input_image must be specified."
    assert model_args.init_model is not None, "init_model must be specified."


    ''' Visualization '''
    # read image
    img = imread(args.input_image, mode='RGB').astype(np.float32)

    # visualize
    visualize(
        img,
        args.target_label,
        args.model_name,
        args.init_model,
        args.n_classes,
        args.save_dir,
        args.gpu
    )