当前位置: 首页>>代码示例>>Python>>正文


Python mxnet.ctx方法代码示例

本文整理汇总了Python中mxnet.ctx方法的典型用法代码示例。如果您正苦于以下问题:Python mxnet.ctx方法的具体用法?Python mxnet.ctx怎么用?Python mxnet.ctx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mxnet的用法示例。


在下文中一共展示了mxnet.ctx方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_images

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def run_images(args,ctx):
    # parse image list
    image_list = [i.strip() for i in args.images.split(',')]
    assert len(image_list) > 0, "No valid image specified to detect"

    network = None if args.deploy_net else args.network
    class_names = parse_class_names(args.class_names)
    data_shape = parse_data_shape(args.data_shape)
    if args.prefix.endswith('_'):
        prefix = args.prefix + args.network + '_' + str(data_shape[0])
    else:
        prefix = args.prefix
    detector = get_detector(network, prefix, args.epoch,
                            data_shape,
                            (args.mean_r, args.mean_g, args.mean_b),
                            ctx, len(class_names), args.nms_thresh, args.force_nms)
    # run detection
    detector.detect_and_visualize(image_list, args.dir, args.extension,
                                  class_names, args.thresh, args.show_timer) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:21,代码来源:demo.py

示例2: __init__

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def __init__(self, symbol, model_prefix, epoch, data_shape, mean_pixels, \
                 batch_size=1, ctx=None):
        self.ctx = ctx
        if self.ctx is None:
            self.ctx = mx.cpu()
        load_symbol, args, auxs = mx.model.load_checkpoint(model_prefix, epoch)
        if symbol is None:
            symbol = load_symbol
        self.mod = mx.mod.Module(symbol, label_names=None, context=self.ctx)
        if not isinstance(data_shape, tuple):
            data_shape = (data_shape, data_shape)
        self.data_shape = data_shape
        self.mod.bind(data_shapes=[('data', (batch_size, 3, data_shape[0], data_shape[1]))])
        self.mod.set_params(args, auxs)
        self.mean_pixels = mean_pixels
        self.mean_pixels_nd = mx.nd.array(mean_pixels).reshape((3,1,1)) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:18,代码来源:detector.py

示例3: get_detector

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def get_detector(net, prefix, epoch, data_shape, mean_pixels, ctx, num_class,
                 nms_thresh=0.5, force_nms=True, nms_topk=400):
    """
    wrapper for initialize a detector

    Parameters:
    ----------
    net : str
        test network name
    prefix : str
        load model prefix
    epoch : int
        load model epoch
    data_shape : int
        resize image shape
    mean_pixels : tuple (float, float, float)
        mean pixel values (R, G, B)
    ctx : mx.ctx
        running context, mx.cpu() or mx.gpu(?)
    num_class : int
        number of classes
    nms_thresh : float
        non-maximum suppression threshold
    force_nms : bool
        force suppress different categories
    """
    if net is not None:
        if isinstance(data_shape, tuple):
            data_shape = data_shape[0]
        net = get_symbol(net, data_shape, num_classes=num_class, nms_thresh=nms_thresh,
            force_nms=force_nms, nms_topk=nms_topk)
    detector = Detector(net, prefix, epoch, data_shape, mean_pixels, ctx=ctx)
    return detector 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:35,代码来源:demo.py

示例4: run_camera

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def run_camera(args,ctx):
    assert args.batch_size == 1, "only batch size of 1 is supported"
    logging.info("Detection threshold is {}".format(args.thresh))
    iter = CameraIterator(frame_resize=parse_frame_resize(args.frame_resize))
    class_names = parse_class_names(args.class_names)
    mean_pixels = (args.mean_r, args.mean_g, args.mean_b)
    data_shape = int(args.data_shape)
    batch_size = int(args.batch_size)
    detector = Detector(
        get_symbol(args.network, data_shape, num_classes=len(class_names)),
        network_path(args.prefix, args.network, data_shape),
        args.epoch,
        data_shape,
        mean_pixels,
        batch_size,
        ctx
    )
    for frame in iter:
        logging.info("Frame info: shape %s type %s", frame.shape, frame.dtype)
        logging.info("Generating batch")
        data_batch = detector.create_batch(frame)
        logging.info("Detecting objects")
        detections_batch = detector.detect_batch(data_batch)
        #detections = [mx.nd.array((1,1,0.2,0.2,0.4,0.4))]
        detections = detections_batch[0]
        logging.info("%d detections", len(detections))
        for det in detections:
            obj = det.asnumpy()
            (klass, score, x0, y0, x1, y1) = obj
            if score > args.thresh:
                draw_detection(frame, obj, class_names)
        cv2.imshow('frame', frame) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:34,代码来源:demo.py

示例5: main

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def main():
    logging.getLogger().setLevel(logging.INFO)
    logging.basicConfig(format='%(asctime)-15s %(message)s')
    args = parse_args()
    if args.cpu:
        ctx = mx.cpu()
    else:
        ctx = mx.gpu(args.gpu_id)

    if args.camera:
        run_camera(args, ctx)
    else:
        run_images(args, ctx)
    return 0 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:16,代码来源:demo.py

示例6: __init__

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def __init__(self, args, num, dim, ctx):
        self.gpu = args.gpu
        self.args = args
        self.trace = []

        self.emb = nd.empty((num, dim), dtype=np.float32, ctx=ctx)
        self.state_sum = nd.zeros((self.emb.shape[0]), dtype=np.float32, ctx=ctx)
        self.state_step = 0 
开发者ID:dmlc,项目名称:dgl,代码行数:10,代码来源:tensor_models.py

示例7: init

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def init(self, emb_init):
        """Initializing the embeddings.

        Parameters
        ----------
        emb_init : float
            The intial embedding range should be [-emb_init, emb_init].
        """
        nd.random.uniform(-emb_init, emb_init,
                          shape=self.emb.shape, dtype=self.emb.dtype,
                          ctx=self.emb.context, out=self.emb) 
开发者ID:dmlc,项目名称:dgl,代码行数:13,代码来源:tensor_models.py

示例8: update

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def update(self, gpu_id=-1):
        """ Update embeddings in a sparse manner
        Sparse embeddings are updated in mini batches. we maintains gradient states for 
        each embedding so they can be updated separately.

        Parameters
        ----------
        gpu_id : int
            Which gpu to accelerate the calculation. if -1 is provided, cpu is used.
        """
        self.state_step += 1
        for idx, data in self.trace:
            grad = data.grad

            clr = self.args.lr
            #clr = self.args.lr / (1 + (self.state_step - 1) * group['lr_decay'])

            # the update is non-linear so indices must be unique
            grad_indices = idx
            grad_values = grad

            grad_sum = (grad_values * grad_values).mean(1)
            ctx = self.state_sum.context
            if ctx != grad_indices.context:
                grad_indices = grad_indices.as_in_context(ctx)
            if ctx != grad_sum.context:
                grad_sum = grad_sum.as_in_context(ctx)
            self.state_sum[grad_indices] += grad_sum
            std = self.state_sum[grad_indices]  # _sparse_mask
            if gpu_id >= 0:
                std = std.as_in_context(mx.gpu(gpu_id))
            std_values = nd.expand_dims(nd.sqrt(std) + 1e-10, 1)
            tmp = (-clr * grad_values / std_values)
            if tmp.context != ctx:
                tmp = tmp.as_in_context(ctx)
            # TODO(zhengda) the overhead is here.
            self.emb[grad_indices] = mx.nd.take(self.emb, grad_indices) + tmp
        self.trace = [] 
开发者ID:dmlc,项目名称:dgl,代码行数:40,代码来源:tensor_models.py

示例9: __init__

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def __init__(self, symbol, model_prefix, epoch, data_shape, mean_pixels, \
                 batch_size=1, ctx=None):
        self.ctx = ctx
        if self.ctx is None:
            self.ctx = mx.cpu()
        load_symbol, args, auxs = mx.model.load_checkpoint(model_prefix, epoch)
        if symbol is None:
            symbol = load_symbol
        self.mod = mx.mod.Module(symbol, label_names=None, context=ctx)
        if not isinstance(data_shape, tuple):
            data_shape = (data_shape, data_shape)
        self.data_shape = data_shape
        self.mod.bind(data_shapes=[('data', (batch_size, 3, data_shape[0], data_shape[1]))])
        self.mod.set_params(args, auxs)
        self.mean_pixels = mean_pixels 
开发者ID:MTCloudVision,项目名称:mxnet-dssd,代码行数:17,代码来源:detector.py

示例10: get_detector

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def get_detector(net, prefix, epoch, data_shape, mean_pixels, ctx,
                 nms_thresh=0.5, force_nms=True):
    """
    wrapper for initialize a detector

    Parameters:
    ----------
    net : str
        test network name
    prefix : str
        load model prefix
    epoch : int
        load model epoch
    data_shape : int
        resize image shape
    mean_pixels : tuple (float, float, float)
        mean pixel values (R, G, B)
    ctx : mx.ctx
        running context, mx.cpu() or mx.gpu(?)
    force_nms : bool
        force suppress different categories
    """
    sys.path.append(os.path.join(os.getcwd(), 'symbol'))
    if net is not None:
        prefix = prefix + "_" + net.strip('_yolo') + '_' + str(data_shape)
        net = importlib.import_module("symbol_" + net) \
            .get_symbol(len(CLASSES), nms_thresh, force_nms)
    detector = Detector(net, prefix, epoch, \
        data_shape, mean_pixels, ctx=ctx)
    return detector 
开发者ID:zhreshold,项目名称:mxnet-yolo,代码行数:32,代码来源:demo.py

示例11: __init__

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def __init__(self, symbol, model_prefix, epoch, data_shape, mean_pixels, \
                 batch_size=1, ctx=None):
        self.ctx = ctx
        if self.ctx is None:
            self.ctx = mx.cpu()
        load_symbol, args, auxs = mx.model.load_checkpoint(model_prefix, epoch)
        if symbol is None:
            symbol = load_symbol
        self.mod = mx.mod.Module(symbol, label_names=("yolo_output_label",), context=ctx)
        self.data_shape = data_shape
        self.mod.bind(data_shapes=[('data', (batch_size, 3, data_shape, data_shape))],
            label_shapes=[('yolo_output_label', (batch_size, 2, 5))])
        self.mod.set_params(args, auxs)
        self.data_shape = data_shape
        self.mean_pixels = mean_pixels 
开发者ID:zhreshold,项目名称:mxnet-yolo,代码行数:17,代码来源:detector.py

示例12: get_detector

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def get_detector(net, prefix, epoch, data_shape, mean_pixels, ctx, num_class,
                 nms_thresh=0.5, force_nms=True, nms_topk=400):
    """
    wrapper for initialize a detector

    Parameters:
    ----------
    net : str
        test network name
    prefix : str
        load model prefix
    epoch : int
        load model epoch
    data_shape : int
        resize image shape
    mean_pixels : tuple (float, float, float)
        mean pixel values (R, G, B)
    ctx : mx.ctx
        running context, mx.cpu() or mx.gpu(?)
    num_class : int
        number of classes
    nms_thresh : float
        non-maximum suppression threshold
    force_nms : bool
        force suppress different categories
    """
    if net is not None:
        net = get_symbol(net, data_shape, num_classes=num_class, nms_thresh=nms_thresh,
            force_nms=force_nms, nms_topk=nms_topk)
    detector = Detector(net, prefix, epoch, data_shape, mean_pixels, ctx=ctx)
    return detector 
开发者ID:zhreshold,项目名称:mxnet-ssd,代码行数:33,代码来源:demo.py

示例13: __init__

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def __init__(self, symbol, model_prefix, epoch, data_shape, mean_pixels, \
                 batch_size=1, ctx=None):
        self.ctx = ctx
        if self.ctx is None:
            self.ctx = mx.cpu()
        load_symbol, args, auxs = mx.model.load_checkpoint(model_prefix, epoch)
        if symbol is None:
            symbol = load_symbol
        self.mod = mx.mod.Module(symbol, label_names=None, context=ctx)
        self.data_shape = data_shape
        self.mod.bind(data_shapes=[('data', (batch_size, 3, data_shape, data_shape))])
        self.mod.set_params(args, auxs)
        self.data_shape = data_shape
        self.mean_pixels = mean_pixels 
开发者ID:zhreshold,项目名称:mxnet-ssd,代码行数:16,代码来源:detector.py

示例14: __init__

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import ctx [as 别名]
def __init__(self, symbol, model_prefix, epoch, data_shape, mean_pixels, \
                 batch_size=1, ctx=None):
        self.ctx = ctx
        if self.ctx is None:
            self.ctx = mx.cpu()
        load_symbol, args, auxs = mx.model.load_checkpoint(model_prefix, epoch)
        if symbol is None:
            symbol = load_symbol
        self.mod = mx.mod.Module(symbol, label_names=None, context=self.ctx)
        if not isinstance(data_shape, tuple):
            data_shape = (data_shape, data_shape)
        self.data_shape = data_shape
        self.mod.bind(data_shapes=[('data', (batch_size, 3, data_shape[0], data_shape[1]))])
        self.mod.set_params(args, auxs)
        self.mean_pixels = mean_pixels 
开发者ID:mahyarnajibi,项目名称:SNIPER-mxnet,代码行数:17,代码来源:detector.py


注:本文中的mxnet.ctx方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。