repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
apache/incubator-mxnet | tools/caffe_converter/caffe_proto_utils.py | read_caffe_mean | def read_caffe_mean(caffe_mean_file):
"""
Reads caffe formatted mean file
:param caffe_mean_file: path to caffe mean file, presumably with 'binaryproto' suffix
:return: mean image, converted from BGR to RGB format
"""
import caffe_parser
import numpy as np
mean_blob = caffe_parser.caffe... | python | def read_caffe_mean(caffe_mean_file):
"""
Reads caffe formatted mean file
:param caffe_mean_file: path to caffe mean file, presumably with 'binaryproto' suffix
:return: mean image, converted from BGR to RGB format
"""
import caffe_parser
import numpy as np
mean_blob = caffe_parser.caffe... | [
"def",
"read_caffe_mean",
"(",
"caffe_mean_file",
")",
":",
"import",
"caffe_parser",
"import",
"numpy",
"as",
"np",
"mean_blob",
"=",
"caffe_parser",
".",
"caffe_pb2",
".",
"BlobProto",
"(",
")",
"with",
"open",
"(",
"caffe_mean_file",
",",
"'rb'",
")",
"as",... | Reads caffe formatted mean file
:param caffe_mean_file: path to caffe mean file, presumably with 'binaryproto' suffix
:return: mean image, converted from BGR to RGB format | [
"Reads",
"caffe",
"formatted",
"mean",
"file",
":",
"param",
"caffe_mean_file",
":",
"path",
"to",
"caffe",
"mean",
"file",
"presumably",
"with",
"binaryproto",
"suffix",
":",
"return",
":",
"mean",
"image",
"converted",
"from",
"BGR",
"to",
"RGB",
"format"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/tools/caffe_converter/caffe_proto_utils.py#L185-L204 | train |
apache/incubator-mxnet | example/gluon/embedding_learning/model.py | get_distance | def get_distance(F, x):
"""Helper function for margin-based loss. Return a distance matrix given a matrix."""
n = x.shape[0]
square = F.sum(x ** 2.0, axis=1, keepdims=True)
distance_square = square + square.transpose() - (2.0 * F.dot(x, x.transpose()))
# Adding identity to make sqrt work.
retu... | python | def get_distance(F, x):
"""Helper function for margin-based loss. Return a distance matrix given a matrix."""
n = x.shape[0]
square = F.sum(x ** 2.0, axis=1, keepdims=True)
distance_square = square + square.transpose() - (2.0 * F.dot(x, x.transpose()))
# Adding identity to make sqrt work.
retu... | [
"def",
"get_distance",
"(",
"F",
",",
"x",
")",
":",
"n",
"=",
"x",
".",
"shape",
"[",
"0",
"]",
"square",
"=",
"F",
".",
"sum",
"(",
"x",
"**",
"2.0",
",",
"axis",
"=",
"1",
",",
"keepdims",
"=",
"True",
")",
"distance_square",
"=",
"square",
... | Helper function for margin-based loss. Return a distance matrix given a matrix. | [
"Helper",
"function",
"for",
"margin",
"-",
"based",
"loss",
".",
"Return",
"a",
"distance",
"matrix",
"given",
"a",
"matrix",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/embedding_learning/model.py#L51-L59 | train |
apache/incubator-mxnet | example/rnn/large_word_lm/model.py | cross_entropy_loss | def cross_entropy_loss(inputs, labels, rescale_loss=1):
""" cross entropy loss with a mask """
criterion = mx.gluon.loss.SoftmaxCrossEntropyLoss(weight=rescale_loss)
loss = criterion(inputs, labels)
mask = S.var('mask')
loss = loss * S.reshape(mask, shape=(-1,))
return S.make_loss(loss.mean()) | python | def cross_entropy_loss(inputs, labels, rescale_loss=1):
""" cross entropy loss with a mask """
criterion = mx.gluon.loss.SoftmaxCrossEntropyLoss(weight=rescale_loss)
loss = criterion(inputs, labels)
mask = S.var('mask')
loss = loss * S.reshape(mask, shape=(-1,))
return S.make_loss(loss.mean()) | [
"def",
"cross_entropy_loss",
"(",
"inputs",
",",
"labels",
",",
"rescale_loss",
"=",
"1",
")",
":",
"criterion",
"=",
"mx",
".",
"gluon",
".",
"loss",
".",
"SoftmaxCrossEntropyLoss",
"(",
"weight",
"=",
"rescale_loss",
")",
"loss",
"=",
"criterion",
"(",
"... | cross entropy loss with a mask | [
"cross",
"entropy",
"loss",
"with",
"a",
"mask"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/rnn/large_word_lm/model.py#L39-L45 | train |
apache/incubator-mxnet | example/rnn/large_word_lm/model.py | rnn | def rnn(bptt, vocab_size, num_embed, nhid, num_layers, dropout, num_proj, batch_size):
""" word embedding + LSTM Projected """
state_names = []
data = S.var('data')
weight = S.var("encoder_weight", stype='row_sparse')
embed = S.sparse.Embedding(data=data, weight=weight, input_dim=vocab_size,
... | python | def rnn(bptt, vocab_size, num_embed, nhid, num_layers, dropout, num_proj, batch_size):
""" word embedding + LSTM Projected """
state_names = []
data = S.var('data')
weight = S.var("encoder_weight", stype='row_sparse')
embed = S.sparse.Embedding(data=data, weight=weight, input_dim=vocab_size,
... | [
"def",
"rnn",
"(",
"bptt",
",",
"vocab_size",
",",
"num_embed",
",",
"nhid",
",",
"num_layers",
",",
"dropout",
",",
"num_proj",
",",
"batch_size",
")",
":",
"state_names",
"=",
"[",
"]",
"data",
"=",
"S",
".",
"var",
"(",
"'data'",
")",
"weight",
"=... | word embedding + LSTM Projected | [
"word",
"embedding",
"+",
"LSTM",
"Projected"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/rnn/large_word_lm/model.py#L47-L72 | train |
apache/incubator-mxnet | example/rnn/large_word_lm/model.py | sampled_softmax | def sampled_softmax(num_classes, num_samples, in_dim, inputs, weight, bias,
sampled_values, remove_accidental_hits=True):
""" Sampled softmax via importance sampling.
This under-estimates the full softmax and is only used for training.
"""
# inputs = (n, in_dim)
... | python | def sampled_softmax(num_classes, num_samples, in_dim, inputs, weight, bias,
sampled_values, remove_accidental_hits=True):
""" Sampled softmax via importance sampling.
This under-estimates the full softmax and is only used for training.
"""
# inputs = (n, in_dim)
... | [
"def",
"sampled_softmax",
"(",
"num_classes",
",",
"num_samples",
",",
"in_dim",
",",
"inputs",
",",
"weight",
",",
"bias",
",",
"sampled_values",
",",
"remove_accidental_hits",
"=",
"True",
")",
":",
"# inputs = (n, in_dim)",
"sample",
",",
"prob_sample",
",",
... | Sampled softmax via importance sampling.
This under-estimates the full softmax and is only used for training. | [
"Sampled",
"softmax",
"via",
"importance",
"sampling",
".",
"This",
"under",
"-",
"estimates",
"the",
"full",
"softmax",
"and",
"is",
"only",
"used",
"for",
"training",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/rnn/large_word_lm/model.py#L74-L128 | train |
apache/incubator-mxnet | example/rnn/large_word_lm/model.py | generate_samples | def generate_samples(label, num_splits, sampler):
""" Split labels into `num_splits` and
generate candidates based on log-uniform distribution.
"""
def listify(x):
return x if isinstance(x, list) else [x]
label_splits = listify(label.split(num_splits, axis=0))
prob_samples = []
p... | python | def generate_samples(label, num_splits, sampler):
""" Split labels into `num_splits` and
generate candidates based on log-uniform distribution.
"""
def listify(x):
return x if isinstance(x, list) else [x]
label_splits = listify(label.split(num_splits, axis=0))
prob_samples = []
p... | [
"def",
"generate_samples",
"(",
"label",
",",
"num_splits",
",",
"sampler",
")",
":",
"def",
"listify",
"(",
"x",
")",
":",
"return",
"x",
"if",
"isinstance",
"(",
"x",
",",
"list",
")",
"else",
"[",
"x",
"]",
"label_splits",
"=",
"listify",
"(",
"la... | Split labels into `num_splits` and
generate candidates based on log-uniform distribution. | [
"Split",
"labels",
"into",
"num_splits",
"and",
"generate",
"candidates",
"based",
"on",
"log",
"-",
"uniform",
"distribution",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/rnn/large_word_lm/model.py#L130-L147 | train |
apache/incubator-mxnet | example/multivariate_time_series/src/lstnet.py | build_iters | def build_iters(data_dir, max_records, q, horizon, splits, batch_size):
"""
Load & generate training examples from multivariate time series data
:return: data iters & variables required to define network architecture
"""
# Read in data as numpy array
df = pd.read_csv(os.path.join(data_dir, "elec... | python | def build_iters(data_dir, max_records, q, horizon, splits, batch_size):
"""
Load & generate training examples from multivariate time series data
:return: data iters & variables required to define network architecture
"""
# Read in data as numpy array
df = pd.read_csv(os.path.join(data_dir, "elec... | [
"def",
"build_iters",
"(",
"data_dir",
",",
"max_records",
",",
"q",
",",
"horizon",
",",
"splits",
",",
"batch_size",
")",
":",
"# Read in data as numpy array",
"df",
"=",
"pd",
".",
"read_csv",
"(",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
... | Load & generate training examples from multivariate time series data
:return: data iters & variables required to define network architecture | [
"Load",
"&",
"generate",
"training",
"examples",
"from",
"multivariate",
"time",
"series",
"data",
":",
"return",
":",
"data",
"iters",
"&",
"variables",
"required",
"to",
"define",
"network",
"architecture"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/multivariate_time_series/src/lstnet.py#L74-L119 | train |
apache/incubator-mxnet | python/mxnet/gluon/model_zoo/vision/__init__.py | get_model | def get_model(name, **kwargs):
"""Returns a pre-defined model by name
Parameters
----------
name : str
Name of the model.
pretrained : bool
Whether to load the pretrained weights for model.
classes : int
Number of classes for the output layer.
ctx : Context, default ... | python | def get_model(name, **kwargs):
"""Returns a pre-defined model by name
Parameters
----------
name : str
Name of the model.
pretrained : bool
Whether to load the pretrained weights for model.
classes : int
Number of classes for the output layer.
ctx : Context, default ... | [
"def",
"get_model",
"(",
"name",
",",
"*",
"*",
"kwargs",
")",
":",
"models",
"=",
"{",
"'resnet18_v1'",
":",
"resnet18_v1",
",",
"'resnet34_v1'",
":",
"resnet34_v1",
",",
"'resnet50_v1'",
":",
"resnet50_v1",
",",
"'resnet101_v1'",
":",
"resnet101_v1",
",",
... | Returns a pre-defined model by name
Parameters
----------
name : str
Name of the model.
pretrained : bool
Whether to load the pretrained weights for model.
classes : int
Number of classes for the output layer.
ctx : Context, default CPU
The context in which to lo... | [
"Returns",
"a",
"pre",
"-",
"defined",
"model",
"by",
"name"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/gluon/model_zoo/vision/__init__.py#L91-L152 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | _new_alloc_handle | def _new_alloc_handle(stype, shape, ctx, delay_alloc, dtype, aux_types, aux_shapes=None):
"""Return a new handle with specified storage type, shape, dtype and context.
Empty handle is only used to hold results
Returns
-------
handle
A new empty ndarray handle
"""
hdl = NDArrayHandl... | python | def _new_alloc_handle(stype, shape, ctx, delay_alloc, dtype, aux_types, aux_shapes=None):
"""Return a new handle with specified storage type, shape, dtype and context.
Empty handle is only used to hold results
Returns
-------
handle
A new empty ndarray handle
"""
hdl = NDArrayHandl... | [
"def",
"_new_alloc_handle",
"(",
"stype",
",",
"shape",
",",
"ctx",
",",
"delay_alloc",
",",
"dtype",
",",
"aux_types",
",",
"aux_shapes",
"=",
"None",
")",
":",
"hdl",
"=",
"NDArrayHandle",
"(",
")",
"for",
"aux_t",
"in",
"aux_types",
":",
"if",
"np",
... | Return a new handle with specified storage type, shape, dtype and context.
Empty handle is only used to hold results
Returns
-------
handle
A new empty ndarray handle | [
"Return",
"a",
"new",
"handle",
"with",
"specified",
"storage",
"type",
"shape",
"dtype",
"and",
"context",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L72-L104 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | _prepare_src_array | def _prepare_src_array(source_array, dtype):
"""Prepare `source_array` so that it can be used to construct NDArray.
`source_array` is converted to a `np.ndarray` if it's neither an `NDArray` \
nor an `np.ndarray`.
"""
if not isinstance(source_array, NDArray) and not isinstance(source_array, np.ndarr... | python | def _prepare_src_array(source_array, dtype):
"""Prepare `source_array` so that it can be used to construct NDArray.
`source_array` is converted to a `np.ndarray` if it's neither an `NDArray` \
nor an `np.ndarray`.
"""
if not isinstance(source_array, NDArray) and not isinstance(source_array, np.ndarr... | [
"def",
"_prepare_src_array",
"(",
"source_array",
",",
"dtype",
")",
":",
"if",
"not",
"isinstance",
"(",
"source_array",
",",
"NDArray",
")",
"and",
"not",
"isinstance",
"(",
"source_array",
",",
"np",
".",
"ndarray",
")",
":",
"try",
":",
"source_array",
... | Prepare `source_array` so that it can be used to construct NDArray.
`source_array` is converted to a `np.ndarray` if it's neither an `NDArray` \
nor an `np.ndarray`. | [
"Prepare",
"source_array",
"so",
"that",
"it",
"can",
"be",
"used",
"to",
"construct",
"NDArray",
".",
"source_array",
"is",
"converted",
"to",
"a",
"np",
".",
"ndarray",
"if",
"it",
"s",
"neither",
"an",
"NDArray",
"\\",
"nor",
"an",
"np",
".",
"ndarray... | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L796-L806 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | _prepare_default_dtype | def _prepare_default_dtype(src_array, dtype):
"""Prepare the value of dtype if `dtype` is None. If `src_array` is an NDArray, numpy.ndarray
or scipy.sparse.csr.csr_matrix, return src_array.dtype. float32 is returned otherwise."""
if dtype is None:
if isinstance(src_array, (NDArray, np.ndarray)):
... | python | def _prepare_default_dtype(src_array, dtype):
"""Prepare the value of dtype if `dtype` is None. If `src_array` is an NDArray, numpy.ndarray
or scipy.sparse.csr.csr_matrix, return src_array.dtype. float32 is returned otherwise."""
if dtype is None:
if isinstance(src_array, (NDArray, np.ndarray)):
... | [
"def",
"_prepare_default_dtype",
"(",
"src_array",
",",
"dtype",
")",
":",
"if",
"dtype",
"is",
"None",
":",
"if",
"isinstance",
"(",
"src_array",
",",
"(",
"NDArray",
",",
"np",
".",
"ndarray",
")",
")",
":",
"dtype",
"=",
"src_array",
".",
"dtype",
"... | Prepare the value of dtype if `dtype` is None. If `src_array` is an NDArray, numpy.ndarray
or scipy.sparse.csr.csr_matrix, return src_array.dtype. float32 is returned otherwise. | [
"Prepare",
"the",
"value",
"of",
"dtype",
"if",
"dtype",
"is",
"None",
".",
"If",
"src_array",
"is",
"an",
"NDArray",
"numpy",
".",
"ndarray",
"or",
"scipy",
".",
"sparse",
".",
"csr",
".",
"csr_matrix",
"return",
"src_array",
".",
"dtype",
".",
"float32... | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L808-L818 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | _check_shape | def _check_shape(s1, s2):
"""check s1 == s2 if both are not None"""
if s1 and s2 and s1 != s2:
raise ValueError("Shape mismatch detected. " + str(s1) + " v.s. " + str(s2)) | python | def _check_shape(s1, s2):
"""check s1 == s2 if both are not None"""
if s1 and s2 and s1 != s2:
raise ValueError("Shape mismatch detected. " + str(s1) + " v.s. " + str(s2)) | [
"def",
"_check_shape",
"(",
"s1",
",",
"s2",
")",
":",
"if",
"s1",
"and",
"s2",
"and",
"s1",
"!=",
"s2",
":",
"raise",
"ValueError",
"(",
"\"Shape mismatch detected. \"",
"+",
"str",
"(",
"s1",
")",
"+",
"\" v.s. \"",
"+",
"str",
"(",
"s2",
")",
")"
... | check s1 == s2 if both are not None | [
"check",
"s1",
"==",
"s2",
"if",
"both",
"are",
"not",
"None"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L820-L823 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | csr_matrix | def csr_matrix(arg1, shape=None, ctx=None, dtype=None):
"""Creates a `CSRNDArray`, an 2D array with compressed sparse row (CSR) format.
The CSRNDArray can be instantiated in several ways:
- csr_matrix(D):
to construct a CSRNDArray with a dense 2D array ``D``
- **D** (*array_like*) - A... | python | def csr_matrix(arg1, shape=None, ctx=None, dtype=None):
"""Creates a `CSRNDArray`, an 2D array with compressed sparse row (CSR) format.
The CSRNDArray can be instantiated in several ways:
- csr_matrix(D):
to construct a CSRNDArray with a dense 2D array ``D``
- **D** (*array_like*) - A... | [
"def",
"csr_matrix",
"(",
"arg1",
",",
"shape",
"=",
"None",
",",
"ctx",
"=",
"None",
",",
"dtype",
"=",
"None",
")",
":",
"# construct a csr matrix from (M, N) or (data, indices, indptr)",
"if",
"isinstance",
"(",
"arg1",
",",
"tuple",
")",
":",
"arg_len",
"=... | Creates a `CSRNDArray`, an 2D array with compressed sparse row (CSR) format.
The CSRNDArray can be instantiated in several ways:
- csr_matrix(D):
to construct a CSRNDArray with a dense 2D array ``D``
- **D** (*array_like*) - An object exposing the array interface, an object whose \
... | [
"Creates",
"a",
"CSRNDArray",
"an",
"2D",
"array",
"with",
"compressed",
"sparse",
"row",
"(",
"CSR",
")",
"format",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L825-L976 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | _csr_matrix_from_definition | def _csr_matrix_from_definition(data, indices, indptr, shape=None, ctx=None,
dtype=None, indices_type=None, indptr_type=None):
"""Create a `CSRNDArray` based on data, indices and indptr"""
# pylint: disable= no-member, protected-access
storage_type = 'csr'
# context
c... | python | def _csr_matrix_from_definition(data, indices, indptr, shape=None, ctx=None,
dtype=None, indices_type=None, indptr_type=None):
"""Create a `CSRNDArray` based on data, indices and indptr"""
# pylint: disable= no-member, protected-access
storage_type = 'csr'
# context
c... | [
"def",
"_csr_matrix_from_definition",
"(",
"data",
",",
"indices",
",",
"indptr",
",",
"shape",
"=",
"None",
",",
"ctx",
"=",
"None",
",",
"dtype",
"=",
"None",
",",
"indices_type",
"=",
"None",
",",
"indptr_type",
"=",
"None",
")",
":",
"# pylint: disable... | Create a `CSRNDArray` based on data, indices and indptr | [
"Create",
"a",
"CSRNDArray",
"based",
"on",
"data",
"indices",
"and",
"indptr"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L978-L1017 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | row_sparse_array | def row_sparse_array(arg1, shape=None, ctx=None, dtype=None):
"""Creates a `RowSparseNDArray`, a multidimensional row sparse array with a set of \
tensor slices at given indices.
The RowSparseNDArray can be instantiated in several ways:
- row_sparse_array(D):
to construct a RowSparseNDArray wi... | python | def row_sparse_array(arg1, shape=None, ctx=None, dtype=None):
"""Creates a `RowSparseNDArray`, a multidimensional row sparse array with a set of \
tensor slices at given indices.
The RowSparseNDArray can be instantiated in several ways:
- row_sparse_array(D):
to construct a RowSparseNDArray wi... | [
"def",
"row_sparse_array",
"(",
"arg1",
",",
"shape",
"=",
"None",
",",
"ctx",
"=",
"None",
",",
"dtype",
"=",
"None",
")",
":",
"# construct a row sparse array from (D0, D1 ..) or (data, indices)",
"if",
"isinstance",
"(",
"arg1",
",",
"tuple",
")",
":",
"arg_l... | Creates a `RowSparseNDArray`, a multidimensional row sparse array with a set of \
tensor slices at given indices.
The RowSparseNDArray can be instantiated in several ways:
- row_sparse_array(D):
to construct a RowSparseNDArray with a dense ndarray ``D``
- **D** (*array_like*) - An object ... | [
"Creates",
"a",
"RowSparseNDArray",
"a",
"multidimensional",
"row",
"sparse",
"array",
"with",
"a",
"set",
"of",
"\\",
"tensor",
"slices",
"at",
"given",
"indices",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L1020-L1140 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | _row_sparse_ndarray_from_definition | def _row_sparse_ndarray_from_definition(data, indices, shape=None, ctx=None,
dtype=None, indices_type=None):
"""Create a `RowSparseNDArray` based on data and indices"""
storage_type = 'row_sparse'
# context
ctx = current_context() if ctx is None else ctx
# typ... | python | def _row_sparse_ndarray_from_definition(data, indices, shape=None, ctx=None,
dtype=None, indices_type=None):
"""Create a `RowSparseNDArray` based on data and indices"""
storage_type = 'row_sparse'
# context
ctx = current_context() if ctx is None else ctx
# typ... | [
"def",
"_row_sparse_ndarray_from_definition",
"(",
"data",
",",
"indices",
",",
"shape",
"=",
"None",
",",
"ctx",
"=",
"None",
",",
"dtype",
"=",
"None",
",",
"indices_type",
"=",
"None",
")",
":",
"storage_type",
"=",
"'row_sparse'",
"# context",
"ctx",
"="... | Create a `RowSparseNDArray` based on data and indices | [
"Create",
"a",
"RowSparseNDArray",
"based",
"on",
"data",
"and",
"indices"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L1142-L1175 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | add | def add(lhs, rhs):
"""Returns element-wise sum of the input arrays with broadcasting.
Equivalent to ``lhs + rhs``, ``mx.nd.broadcast_add(lhs, rhs)`` and
``mx.nd.broadcast_plus(lhs, rhs)`` when shapes of lhs and rhs do not
match. If lhs.shape == rhs.shape, this is equivalent to
``mx.nd.elemwise_add(... | python | def add(lhs, rhs):
"""Returns element-wise sum of the input arrays with broadcasting.
Equivalent to ``lhs + rhs``, ``mx.nd.broadcast_add(lhs, rhs)`` and
``mx.nd.broadcast_plus(lhs, rhs)`` when shapes of lhs and rhs do not
match. If lhs.shape == rhs.shape, this is equivalent to
``mx.nd.elemwise_add(... | [
"def",
"add",
"(",
"lhs",
",",
"rhs",
")",
":",
"# pylint: disable= no-member, protected-access",
"if",
"isinstance",
"(",
"lhs",
",",
"NDArray",
")",
"and",
"isinstance",
"(",
"rhs",
",",
"NDArray",
")",
"and",
"lhs",
".",
"shape",
"==",
"rhs",
".",
"shap... | Returns element-wise sum of the input arrays with broadcasting.
Equivalent to ``lhs + rhs``, ``mx.nd.broadcast_add(lhs, rhs)`` and
``mx.nd.broadcast_plus(lhs, rhs)`` when shapes of lhs and rhs do not
match. If lhs.shape == rhs.shape, this is equivalent to
``mx.nd.elemwise_add(lhs, rhs)``
.. note::... | [
"Returns",
"element",
"-",
"wise",
"sum",
"of",
"the",
"input",
"arrays",
"with",
"broadcasting",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L1193-L1261 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | subtract | def subtract(lhs, rhs):
"""Returns element-wise difference of the input arrays with broadcasting.
Equivalent to ``lhs - rhs``, ``mx.nd.broadcast_sub(lhs, rhs)`` and
``mx.nd.broadcast_minus(lhs, rhs)`` when shapes of lhs and rhs do not
match. If lhs.shape == rhs.shape, this is equivalent to
``mx.nd.... | python | def subtract(lhs, rhs):
"""Returns element-wise difference of the input arrays with broadcasting.
Equivalent to ``lhs - rhs``, ``mx.nd.broadcast_sub(lhs, rhs)`` and
``mx.nd.broadcast_minus(lhs, rhs)`` when shapes of lhs and rhs do not
match. If lhs.shape == rhs.shape, this is equivalent to
``mx.nd.... | [
"def",
"subtract",
"(",
"lhs",
",",
"rhs",
")",
":",
"# pylint: disable= no-member, protected-access",
"if",
"isinstance",
"(",
"lhs",
",",
"NDArray",
")",
"and",
"isinstance",
"(",
"rhs",
",",
"NDArray",
")",
"and",
"lhs",
".",
"shape",
"==",
"rhs",
".",
... | Returns element-wise difference of the input arrays with broadcasting.
Equivalent to ``lhs - rhs``, ``mx.nd.broadcast_sub(lhs, rhs)`` and
``mx.nd.broadcast_minus(lhs, rhs)`` when shapes of lhs and rhs do not
match. If lhs.shape == rhs.shape, this is equivalent to
``mx.nd.elemwise_sub(lhs, rhs)``
.... | [
"Returns",
"element",
"-",
"wise",
"difference",
"of",
"the",
"input",
"arrays",
"with",
"broadcasting",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L1265-L1333 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | multiply | def multiply(lhs, rhs):
"""Returns element-wise product of the input arrays with broadcasting.
Equivalent to ``lhs * rhs`` and ``mx.nd.broadcast_mul(lhs, rhs)``
when shapes of lhs and rhs do not match. If lhs.shape == rhs.shape,
this is equivalent to ``mx.nd.elemwise_mul(lhs, rhs)``
..... | python | def multiply(lhs, rhs):
"""Returns element-wise product of the input arrays with broadcasting.
Equivalent to ``lhs * rhs`` and ``mx.nd.broadcast_mul(lhs, rhs)``
when shapes of lhs and rhs do not match. If lhs.shape == rhs.shape,
this is equivalent to ``mx.nd.elemwise_mul(lhs, rhs)``
..... | [
"def",
"multiply",
"(",
"lhs",
",",
"rhs",
")",
":",
"# pylint: disable= no-member, protected-access",
"if",
"isinstance",
"(",
"lhs",
",",
"NDArray",
")",
"and",
"isinstance",
"(",
"rhs",
",",
"NDArray",
")",
"and",
"lhs",
".",
"shape",
"==",
"rhs",
".",
... | Returns element-wise product of the input arrays with broadcasting.
Equivalent to ``lhs * rhs`` and ``mx.nd.broadcast_mul(lhs, rhs)``
when shapes of lhs and rhs do not match. If lhs.shape == rhs.shape,
this is equivalent to ``mx.nd.elemwise_mul(lhs, rhs)``
.. note::
If the corresp... | [
"Returns",
"element",
"-",
"wise",
"product",
"of",
"the",
"input",
"arrays",
"with",
"broadcasting",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L1337-L1417 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | divide | def divide(lhs, rhs):
"""Returns element-wise division of the input arrays with broadcasting.
Equivalent to ``lhs / rhs`` and ``mx.nd.broadcast_div(lhs, rhs)``
when shapes of lhs and rhs do not match. If lhs.shape == rhs.shape,
this is equivalent to ``mx.nd.elemwise_div(lhs, rhs)``
.. note::
... | python | def divide(lhs, rhs):
"""Returns element-wise division of the input arrays with broadcasting.
Equivalent to ``lhs / rhs`` and ``mx.nd.broadcast_div(lhs, rhs)``
when shapes of lhs and rhs do not match. If lhs.shape == rhs.shape,
this is equivalent to ``mx.nd.elemwise_div(lhs, rhs)``
.. note::
... | [
"def",
"divide",
"(",
"lhs",
",",
"rhs",
")",
":",
"# pylint: disable= no-member, protected-access",
"if",
"isinstance",
"(",
"lhs",
",",
"NDArray",
")",
"and",
"isinstance",
"(",
"rhs",
",",
"NDArray",
")",
"and",
"lhs",
".",
"shape",
"==",
"rhs",
".",
"s... | Returns element-wise division of the input arrays with broadcasting.
Equivalent to ``lhs / rhs`` and ``mx.nd.broadcast_div(lhs, rhs)``
when shapes of lhs and rhs do not match. If lhs.shape == rhs.shape,
this is equivalent to ``mx.nd.elemwise_div(lhs, rhs)``
.. note::
If the corresponding dime... | [
"Returns",
"element",
"-",
"wise",
"division",
"of",
"the",
"input",
"arrays",
"with",
"broadcasting",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L1421-L1503 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | zeros | def zeros(stype, shape, ctx=None, dtype=None, **kwargs):
"""Return a new array of given shape and type, filled with zeros.
Parameters
----------
stype: string
The storage type of the empty array, such as 'row_sparse', 'csr', etc
shape : int or tuple of int
The shape of the empty arr... | python | def zeros(stype, shape, ctx=None, dtype=None, **kwargs):
"""Return a new array of given shape and type, filled with zeros.
Parameters
----------
stype: string
The storage type of the empty array, such as 'row_sparse', 'csr', etc
shape : int or tuple of int
The shape of the empty arr... | [
"def",
"zeros",
"(",
"stype",
",",
"shape",
",",
"ctx",
"=",
"None",
",",
"dtype",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# pylint: disable= no-member, protected-access",
"if",
"stype",
"==",
"'default'",
":",
"return",
"_zeros_ndarray",
"(",
"shap... | Return a new array of given shape and type, filled with zeros.
Parameters
----------
stype: string
The storage type of the empty array, such as 'row_sparse', 'csr', etc
shape : int or tuple of int
The shape of the empty array
ctx : Context, optional
An optional device contex... | [
"Return",
"a",
"new",
"array",
"of",
"given",
"shape",
"and",
"type",
"filled",
"with",
"zeros",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L1507-L1543 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | empty | def empty(stype, shape, ctx=None, dtype=None):
"""Returns a new array of given shape and type, without initializing entries.
Parameters
----------
stype: string
The storage type of the empty array, such as 'row_sparse', 'csr', etc
shape : int or tuple of int
The shape of the empty a... | python | def empty(stype, shape, ctx=None, dtype=None):
"""Returns a new array of given shape and type, without initializing entries.
Parameters
----------
stype: string
The storage type of the empty array, such as 'row_sparse', 'csr', etc
shape : int or tuple of int
The shape of the empty a... | [
"def",
"empty",
"(",
"stype",
",",
"shape",
",",
"ctx",
"=",
"None",
",",
"dtype",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"shape",
",",
"int",
")",
":",
"shape",
"=",
"(",
"shape",
",",
")",
"if",
"ctx",
"is",
"None",
":",
"ctx",
"=",
... | Returns a new array of given shape and type, without initializing entries.
Parameters
----------
stype: string
The storage type of the empty array, such as 'row_sparse', 'csr', etc
shape : int or tuple of int
The shape of the empty array.
ctx : Context, optional
An optional ... | [
"Returns",
"a",
"new",
"array",
"of",
"given",
"shape",
"and",
"type",
"without",
"initializing",
"entries",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L1547-L1576 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | array | def array(source_array, ctx=None, dtype=None):
"""Creates a sparse array from any object exposing the array interface.
Parameters
----------
source_array : RowSparseNDArray, CSRNDArray or scipy.sparse.csr.csr_matrix
The source sparse array
ctx : Context, optional
The default context... | python | def array(source_array, ctx=None, dtype=None):
"""Creates a sparse array from any object exposing the array interface.
Parameters
----------
source_array : RowSparseNDArray, CSRNDArray or scipy.sparse.csr.csr_matrix
The source sparse array
ctx : Context, optional
The default context... | [
"def",
"array",
"(",
"source_array",
",",
"ctx",
"=",
"None",
",",
"dtype",
"=",
"None",
")",
":",
"ctx",
"=",
"current_context",
"(",
")",
"if",
"ctx",
"is",
"None",
"else",
"ctx",
"if",
"isinstance",
"(",
"source_array",
",",
"NDArray",
")",
":",
"... | Creates a sparse array from any object exposing the array interface.
Parameters
----------
source_array : RowSparseNDArray, CSRNDArray or scipy.sparse.csr.csr_matrix
The source sparse array
ctx : Context, optional
The default context is ``source_array.context`` if ``source_array`` is an... | [
"Creates",
"a",
"sparse",
"array",
"from",
"any",
"object",
"exposing",
"the",
"array",
"interface",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L1579-L1637 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | BaseSparseNDArray._aux_type | def _aux_type(self, i):
"""Data-type of the array's ith aux data.
Returns
-------
numpy.dtype
This BaseSparseNDArray's aux data type.
"""
aux_type = ctypes.c_int()
check_call(_LIB.MXNDArrayGetAuxType(self.handle, i, ctypes.byref(aux_type)))
re... | python | def _aux_type(self, i):
"""Data-type of the array's ith aux data.
Returns
-------
numpy.dtype
This BaseSparseNDArray's aux data type.
"""
aux_type = ctypes.c_int()
check_call(_LIB.MXNDArrayGetAuxType(self.handle, i, ctypes.byref(aux_type)))
re... | [
"def",
"_aux_type",
"(",
"self",
",",
"i",
")",
":",
"aux_type",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"check_call",
"(",
"_LIB",
".",
"MXNDArrayGetAuxType",
"(",
"self",
".",
"handle",
",",
"i",
",",
"ctypes",
".",
"byref",
"(",
"aux_type",
")",
")... | Data-type of the array's ith aux data.
Returns
-------
numpy.dtype
This BaseSparseNDArray's aux data type. | [
"Data",
"-",
"type",
"of",
"the",
"array",
"s",
"ith",
"aux",
"data",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L164-L174 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | BaseSparseNDArray._aux_types | def _aux_types(self):
"""The data types of the aux data for the BaseSparseNDArray.
"""
aux_types = []
num_aux = self._num_aux
for i in range(num_aux):
aux_types.append(self._aux_type(i))
return aux_types | python | def _aux_types(self):
"""The data types of the aux data for the BaseSparseNDArray.
"""
aux_types = []
num_aux = self._num_aux
for i in range(num_aux):
aux_types.append(self._aux_type(i))
return aux_types | [
"def",
"_aux_types",
"(",
"self",
")",
":",
"aux_types",
"=",
"[",
"]",
"num_aux",
"=",
"self",
".",
"_num_aux",
"for",
"i",
"in",
"range",
"(",
"num_aux",
")",
":",
"aux_types",
".",
"append",
"(",
"self",
".",
"_aux_type",
"(",
"i",
")",
")",
"re... | The data types of the aux data for the BaseSparseNDArray. | [
"The",
"data",
"types",
"of",
"the",
"aux",
"data",
"for",
"the",
"BaseSparseNDArray",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L183-L190 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | BaseSparseNDArray.astype | def astype(self, dtype, copy=True):
"""Return a copy of the array after casting to a specified type.
Parameters
----------
dtype : numpy.dtype or str
The type of the returned array.
copy : bool
Default `True`. By default, astype always returns a newly
... | python | def astype(self, dtype, copy=True):
"""Return a copy of the array after casting to a specified type.
Parameters
----------
dtype : numpy.dtype or str
The type of the returned array.
copy : bool
Default `True`. By default, astype always returns a newly
... | [
"def",
"astype",
"(",
"self",
",",
"dtype",
",",
"copy",
"=",
"True",
")",
":",
"if",
"not",
"copy",
"and",
"np",
".",
"dtype",
"(",
"dtype",
")",
"==",
"self",
".",
"dtype",
":",
"return",
"self",
"res",
"=",
"zeros",
"(",
"shape",
"=",
"self",
... | Return a copy of the array after casting to a specified type.
Parameters
----------
dtype : numpy.dtype or str
The type of the returned array.
copy : bool
Default `True`. By default, astype always returns a newly
allocated ndarray on the same context.... | [
"Return",
"a",
"copy",
"of",
"the",
"array",
"after",
"casting",
"to",
"a",
"specified",
"type",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L197-L223 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | BaseSparseNDArray.check_format | def check_format(self, full_check=True):
"""Check whether the NDArray format is valid.
Parameters
----------
full_check : bool, optional
If `True`, rigorous check, O(N) operations. Otherwise
basic check, O(1) operations (default True).
"""
check_c... | python | def check_format(self, full_check=True):
"""Check whether the NDArray format is valid.
Parameters
----------
full_check : bool, optional
If `True`, rigorous check, O(N) operations. Otherwise
basic check, O(1) operations (default True).
"""
check_c... | [
"def",
"check_format",
"(",
"self",
",",
"full_check",
"=",
"True",
")",
":",
"check_call",
"(",
"_LIB",
".",
"MXNDArraySyncCheckFormat",
"(",
"self",
".",
"handle",
",",
"ctypes",
".",
"c_bool",
"(",
"full_check",
")",
")",
")"
] | Check whether the NDArray format is valid.
Parameters
----------
full_check : bool, optional
If `True`, rigorous check, O(N) operations. Otherwise
basic check, O(1) operations (default True). | [
"Check",
"whether",
"the",
"NDArray",
"format",
"is",
"valid",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L252-L261 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | BaseSparseNDArray._data | def _data(self):
"""A deep copy NDArray of the data array associated with the BaseSparseNDArray.
This function blocks. Do not use it in performance critical code.
"""
self.wait_to_read()
hdl = NDArrayHandle()
check_call(_LIB.MXNDArrayGetDataNDArray(self.handle, ctypes.by... | python | def _data(self):
"""A deep copy NDArray of the data array associated with the BaseSparseNDArray.
This function blocks. Do not use it in performance critical code.
"""
self.wait_to_read()
hdl = NDArrayHandle()
check_call(_LIB.MXNDArrayGetDataNDArray(self.handle, ctypes.by... | [
"def",
"_data",
"(",
"self",
")",
":",
"self",
".",
"wait_to_read",
"(",
")",
"hdl",
"=",
"NDArrayHandle",
"(",
")",
"check_call",
"(",
"_LIB",
".",
"MXNDArrayGetDataNDArray",
"(",
"self",
".",
"handle",
",",
"ctypes",
".",
"byref",
"(",
"hdl",
")",
")... | A deep copy NDArray of the data array associated with the BaseSparseNDArray.
This function blocks. Do not use it in performance critical code. | [
"A",
"deep",
"copy",
"NDArray",
"of",
"the",
"data",
"array",
"associated",
"with",
"the",
"BaseSparseNDArray",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L263-L271 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | BaseSparseNDArray._aux_data | def _aux_data(self, i):
""" Get a deep copy NDArray of the i-th aux data array associated with the
BaseSparseNDArray.
This function blocks. Do not use it in performance critical code.
"""
self.wait_to_read()
hdl = NDArrayHandle()
check_call(_LIB.MXNDArrayGetAuxND... | python | def _aux_data(self, i):
""" Get a deep copy NDArray of the i-th aux data array associated with the
BaseSparseNDArray.
This function blocks. Do not use it in performance critical code.
"""
self.wait_to_read()
hdl = NDArrayHandle()
check_call(_LIB.MXNDArrayGetAuxND... | [
"def",
"_aux_data",
"(",
"self",
",",
"i",
")",
":",
"self",
".",
"wait_to_read",
"(",
")",
"hdl",
"=",
"NDArrayHandle",
"(",
")",
"check_call",
"(",
"_LIB",
".",
"MXNDArrayGetAuxNDArray",
"(",
"self",
".",
"handle",
",",
"i",
",",
"ctypes",
".",
"byre... | Get a deep copy NDArray of the i-th aux data array associated with the
BaseSparseNDArray.
This function blocks. Do not use it in performance critical code. | [
"Get",
"a",
"deep",
"copy",
"NDArray",
"of",
"the",
"i",
"-",
"th",
"aux",
"data",
"array",
"associated",
"with",
"the",
"BaseSparseNDArray",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L274-L283 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | CSRNDArray.asscipy | def asscipy(self):
"""Returns a ``scipy.sparse.csr.csr_matrix`` object with value copied from this array
Examples
--------
>>> x = mx.nd.sparse.zeros('csr', (2,3))
>>> y = x.asscipy()
>>> type(y)
<type 'scipy.sparse.csr.csr_matrix'>
>>> y
<2x3 spa... | python | def asscipy(self):
"""Returns a ``scipy.sparse.csr.csr_matrix`` object with value copied from this array
Examples
--------
>>> x = mx.nd.sparse.zeros('csr', (2,3))
>>> y = x.asscipy()
>>> type(y)
<type 'scipy.sparse.csr.csr_matrix'>
>>> y
<2x3 spa... | [
"def",
"asscipy",
"(",
"self",
")",
":",
"data",
"=",
"self",
".",
"data",
".",
"asnumpy",
"(",
")",
"indices",
"=",
"self",
".",
"indices",
".",
"asnumpy",
"(",
")",
"indptr",
"=",
"self",
".",
"indptr",
".",
"asnumpy",
"(",
")",
"if",
"not",
"s... | Returns a ``scipy.sparse.csr.csr_matrix`` object with value copied from this array
Examples
--------
>>> x = mx.nd.sparse.zeros('csr', (2,3))
>>> y = x.asscipy()
>>> type(y)
<type 'scipy.sparse.csr.csr_matrix'>
>>> y
<2x3 sparse matrix of type '<type 'num... | [
"Returns",
"a",
"scipy",
".",
"sparse",
".",
"csr",
".",
"csr_matrix",
"object",
"with",
"value",
"copied",
"from",
"this",
"array"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L539-L558 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | RowSparseNDArray.tostype | def tostype(self, stype):
"""Return a copy of the array with chosen storage type.
Returns
-------
NDArray or RowSparseNDArray
A copy of the array with the chosen storage stype
"""
# pylint: disable= no-member, protected-access
if stype == 'csr':
... | python | def tostype(self, stype):
"""Return a copy of the array with chosen storage type.
Returns
-------
NDArray or RowSparseNDArray
A copy of the array with the chosen storage stype
"""
# pylint: disable= no-member, protected-access
if stype == 'csr':
... | [
"def",
"tostype",
"(",
"self",
",",
"stype",
")",
":",
"# pylint: disable= no-member, protected-access",
"if",
"stype",
"==",
"'csr'",
":",
"raise",
"ValueError",
"(",
"\"cast_storage from row_sparse to csr is not supported\"",
")",
"return",
"op",
".",
"cast_storage",
... | Return a copy of the array with chosen storage type.
Returns
-------
NDArray or RowSparseNDArray
A copy of the array with the chosen storage stype | [
"Return",
"a",
"copy",
"of",
"the",
"array",
"with",
"chosen",
"storage",
"type",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L740-L751 | train |
apache/incubator-mxnet | python/mxnet/ndarray/sparse.py | RowSparseNDArray.copyto | def copyto(self, other):
"""Copies the value of this array to another array.
If ``other`` is a ``NDArray`` or ``RowSparseNDArray`` object, then ``other.shape``
and ``self.shape`` should be the same. This function copies the value from
``self`` to ``other``.
If ``other`` is a co... | python | def copyto(self, other):
"""Copies the value of this array to another array.
If ``other`` is a ``NDArray`` or ``RowSparseNDArray`` object, then ``other.shape``
and ``self.shape`` should be the same. This function copies the value from
``self`` to ``other``.
If ``other`` is a co... | [
"def",
"copyto",
"(",
"self",
",",
"other",
")",
":",
"if",
"isinstance",
"(",
"other",
",",
"Context",
")",
":",
"return",
"super",
"(",
"RowSparseNDArray",
",",
"self",
")",
".",
"copyto",
"(",
"other",
")",
"elif",
"isinstance",
"(",
"other",
",",
... | Copies the value of this array to another array.
If ``other`` is a ``NDArray`` or ``RowSparseNDArray`` object, then ``other.shape``
and ``self.shape`` should be the same. This function copies the value from
``self`` to ``other``.
If ``other`` is a context, a new ``RowSparseNDArray`` wi... | [
"Copies",
"the",
"value",
"of",
"this",
"array",
"to",
"another",
"array",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/ndarray/sparse.py#L754-L784 | train |
apache/incubator-mxnet | python/mxnet/contrib/onnx/mx2onnx/export_model.py | export_model | def export_model(sym, params, input_shape, input_type=np.float32,
onnx_file_path='model.onnx', verbose=False):
"""Exports the MXNet model file, passed as a parameter, into ONNX model.
Accepts both symbol,parameter objects as well as json and params filepaths as input.
Operator support and c... | python | def export_model(sym, params, input_shape, input_type=np.float32,
onnx_file_path='model.onnx', verbose=False):
"""Exports the MXNet model file, passed as a parameter, into ONNX model.
Accepts both symbol,parameter objects as well as json and params filepaths as input.
Operator support and c... | [
"def",
"export_model",
"(",
"sym",
",",
"params",
",",
"input_shape",
",",
"input_type",
"=",
"np",
".",
"float32",
",",
"onnx_file_path",
"=",
"'model.onnx'",
",",
"verbose",
"=",
"False",
")",
":",
"try",
":",
"from",
"onnx",
"import",
"helper",
",",
"... | Exports the MXNet model file, passed as a parameter, into ONNX model.
Accepts both symbol,parameter objects as well as json and params filepaths as input.
Operator support and coverage -
https://cwiki.apache.org/confluence/display/MXNET/MXNet-ONNX+Integration
Parameters
----------
sym : str or ... | [
"Exports",
"the",
"MXNet",
"model",
"file",
"passed",
"as",
"a",
"parameter",
"into",
"ONNX",
"model",
".",
"Accepts",
"both",
"symbol",
"parameter",
"objects",
"as",
"well",
"as",
"json",
"and",
"params",
"filepaths",
"as",
"input",
".",
"Operator",
"suppor... | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/onnx/mx2onnx/export_model.py#L35-L101 | train |
apache/incubator-mxnet | benchmark/python/sparse/memory_benchmark.py | bench_dot | def bench_dot(lhs_row_dim, lhs_col_dim, rhs_col_dim, density,
rhs_density, dot_func, trans_lhs, lhs_stype,
rhs_stype, only_storage, distribution="uniform"):
""" Benchmarking both storage and dot
"""
lhs_nd = rand_ndarray((lhs_row_dim, lhs_col_dim), lhs_stype, density, distributio... | python | def bench_dot(lhs_row_dim, lhs_col_dim, rhs_col_dim, density,
rhs_density, dot_func, trans_lhs, lhs_stype,
rhs_stype, only_storage, distribution="uniform"):
""" Benchmarking both storage and dot
"""
lhs_nd = rand_ndarray((lhs_row_dim, lhs_col_dim), lhs_stype, density, distributio... | [
"def",
"bench_dot",
"(",
"lhs_row_dim",
",",
"lhs_col_dim",
",",
"rhs_col_dim",
",",
"density",
",",
"rhs_density",
",",
"dot_func",
",",
"trans_lhs",
",",
"lhs_stype",
",",
"rhs_stype",
",",
"only_storage",
",",
"distribution",
"=",
"\"uniform\"",
")",
":",
"... | Benchmarking both storage and dot | [
"Benchmarking",
"both",
"storage",
"and",
"dot"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/benchmark/python/sparse/memory_benchmark.py#L79-L89 | train |
apache/incubator-mxnet | tools/caffe_converter/convert_mean.py | convert_mean | def convert_mean(binaryproto_fname, output=None):
"""Convert caffe mean
Parameters
----------
binaryproto_fname : str
Filename of the mean
output : str, optional
Save the mean into mxnet's format
Returns
-------
NDArray
Mean in ndarray
"""
mean_blob = ca... | python | def convert_mean(binaryproto_fname, output=None):
"""Convert caffe mean
Parameters
----------
binaryproto_fname : str
Filename of the mean
output : str, optional
Save the mean into mxnet's format
Returns
-------
NDArray
Mean in ndarray
"""
mean_blob = ca... | [
"def",
"convert_mean",
"(",
"binaryproto_fname",
",",
"output",
"=",
"None",
")",
":",
"mean_blob",
"=",
"caffe_parser",
".",
"caffe_pb2",
".",
"BlobProto",
"(",
")",
"with",
"open",
"(",
"binaryproto_fname",
",",
"'rb'",
")",
"as",
"f",
":",
"mean_blob",
... | Convert caffe mean
Parameters
----------
binaryproto_fname : str
Filename of the mean
output : str, optional
Save the mean into mxnet's format
Returns
-------
NDArray
Mean in ndarray | [
"Convert",
"caffe",
"mean"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/tools/caffe_converter/convert_mean.py#L25-L53 | train |
apache/incubator-mxnet | python/mxnet/gluon/model_zoo/vision/densenet.py | get_densenet | def get_densenet(num_layers, pretrained=False, ctx=cpu(),
root=os.path.join(base.data_dir(), 'models'), **kwargs):
r"""Densenet-BC model from the
`"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_ paper.
Parameters
----------
num_layers : int
... | python | def get_densenet(num_layers, pretrained=False, ctx=cpu(),
root=os.path.join(base.data_dir(), 'models'), **kwargs):
r"""Densenet-BC model from the
`"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_ paper.
Parameters
----------
num_layers : int
... | [
"def",
"get_densenet",
"(",
"num_layers",
",",
"pretrained",
"=",
"False",
",",
"ctx",
"=",
"cpu",
"(",
")",
",",
"root",
"=",
"os",
".",
"path",
".",
"join",
"(",
"base",
".",
"data_dir",
"(",
")",
",",
"'models'",
")",
",",
"*",
"*",
"kwargs",
... | r"""Densenet-BC model from the
`"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_ paper.
Parameters
----------
num_layers : int
Number of layers for the variant of densenet. Options are 121, 161, 169, 201.
pretrained : bool, default False
Whether to... | [
"r",
"Densenet",
"-",
"BC",
"model",
"from",
"the",
"Densely",
"Connected",
"Convolutional",
"Networks",
"<https",
":",
"//",
"arxiv",
".",
"org",
"/",
"pdf",
"/",
"1608",
".",
"06993",
".",
"pdf",
">",
"_",
"paper",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/gluon/model_zoo/vision/densenet.py#L125-L146 | train |
apache/incubator-mxnet | python/mxnet/contrib/onnx/mx2onnx/_export_helper.py | load_module | def load_module(sym_filepath, params_filepath):
"""Loads the MXNet model file and
returns MXNet symbol and params (weights).
Parameters
----------
json_path : str
Path to the json file
params_path : str
Path to the params file
Returns
-------
sym : MXNet symbol
... | python | def load_module(sym_filepath, params_filepath):
"""Loads the MXNet model file and
returns MXNet symbol and params (weights).
Parameters
----------
json_path : str
Path to the json file
params_path : str
Path to the params file
Returns
-------
sym : MXNet symbol
... | [
"def",
"load_module",
"(",
"sym_filepath",
",",
"params_filepath",
")",
":",
"if",
"not",
"(",
"os",
".",
"path",
".",
"isfile",
"(",
"sym_filepath",
")",
"and",
"os",
".",
"path",
".",
"isfile",
"(",
"params_filepath",
")",
")",
":",
"raise",
"ValueErro... | Loads the MXNet model file and
returns MXNet symbol and params (weights).
Parameters
----------
json_path : str
Path to the json file
params_path : str
Path to the params file
Returns
-------
sym : MXNet symbol
Model symbol object
params : params object
... | [
"Loads",
"the",
"MXNet",
"model",
"file",
"and",
"returns",
"MXNet",
"symbol",
"and",
"params",
"(",
"weights",
")",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/onnx/mx2onnx/_export_helper.py#L24-L65 | train |
apache/incubator-mxnet | example/ssd/symbol/symbol_builder.py | import_module | def import_module(module_name):
"""Helper function to import module"""
import sys, os
import importlib
sys.path.append(os.path.dirname(__file__))
return importlib.import_module(module_name) | python | def import_module(module_name):
"""Helper function to import module"""
import sys, os
import importlib
sys.path.append(os.path.dirname(__file__))
return importlib.import_module(module_name) | [
"def",
"import_module",
"(",
"module_name",
")",
":",
"import",
"sys",
",",
"os",
"import",
"importlib",
"sys",
".",
"path",
".",
"append",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
")",
"return",
"importlib",
".",
"import_module",
"(... | Helper function to import module | [
"Helper",
"function",
"to",
"import",
"module"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/symbol/symbol_builder.py#L22-L27 | train |
apache/incubator-mxnet | example/ssd/symbol/symbol_builder.py | get_symbol_train | def get_symbol_train(network, num_classes, from_layers, num_filters, strides, pads,
sizes, ratios, normalizations=-1, steps=[], min_filter=128,
nms_thresh=0.5, force_suppress=False, nms_topk=400, **kwargs):
"""Build network symbol for training SSD
Parameters
------... | python | def get_symbol_train(network, num_classes, from_layers, num_filters, strides, pads,
sizes, ratios, normalizations=-1, steps=[], min_filter=128,
nms_thresh=0.5, force_suppress=False, nms_topk=400, **kwargs):
"""Build network symbol for training SSD
Parameters
------... | [
"def",
"get_symbol_train",
"(",
"network",
",",
"num_classes",
",",
"from_layers",
",",
"num_filters",
",",
"strides",
",",
"pads",
",",
"sizes",
",",
"ratios",
",",
"normalizations",
"=",
"-",
"1",
",",
"steps",
"=",
"[",
"]",
",",
"min_filter",
"=",
"1... | Build network symbol for training SSD
Parameters
----------
network : str
base network symbol name
num_classes : int
number of object classes not including background
from_layers : list of str
feature extraction layers, use '' for add extra layers
For example:
... | [
"Build",
"network",
"symbol",
"for",
"training",
"SSD"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/symbol/symbol_builder.py#L29-L116 | train |
apache/incubator-mxnet | example/ssd/symbol/symbol_builder.py | get_symbol | def get_symbol(network, num_classes, from_layers, num_filters, sizes, ratios,
strides, pads, normalizations=-1, steps=[], min_filter=128,
nms_thresh=0.5, force_suppress=False, nms_topk=400, **kwargs):
"""Build network for testing SSD
Parameters
----------
network : str
... | python | def get_symbol(network, num_classes, from_layers, num_filters, sizes, ratios,
strides, pads, normalizations=-1, steps=[], min_filter=128,
nms_thresh=0.5, force_suppress=False, nms_topk=400, **kwargs):
"""Build network for testing SSD
Parameters
----------
network : str
... | [
"def",
"get_symbol",
"(",
"network",
",",
"num_classes",
",",
"from_layers",
",",
"num_filters",
",",
"sizes",
",",
"ratios",
",",
"strides",
",",
"pads",
",",
"normalizations",
"=",
"-",
"1",
",",
"steps",
"=",
"[",
"]",
",",
"min_filter",
"=",
"128",
... | Build network for testing SSD
Parameters
----------
network : str
base network symbol name
num_classes : int
number of object classes not including background
from_layers : list of str
feature extraction layers, use '' for add extra layers
For example:
from_l... | [
"Build",
"network",
"for",
"testing",
"SSD"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/symbol/symbol_builder.py#L118-L182 | train |
apache/incubator-mxnet | docs/tutorial_utils/vision/cnn_visualization/gradcam.py | _get_grad | def _get_grad(net, image, class_id=None, conv_layer_name=None, image_grad=False):
"""This is an internal helper function that can be used for either of these
but not both at the same time:
1. Record the output and gradient of output of an intermediate convolutional layer.
2. Record the gradients of the ... | python | def _get_grad(net, image, class_id=None, conv_layer_name=None, image_grad=False):
"""This is an internal helper function that can be used for either of these
but not both at the same time:
1. Record the output and gradient of output of an intermediate convolutional layer.
2. Record the gradients of the ... | [
"def",
"_get_grad",
"(",
"net",
",",
"image",
",",
"class_id",
"=",
"None",
",",
"conv_layer_name",
"=",
"None",
",",
"image_grad",
"=",
"False",
")",
":",
"if",
"image_grad",
":",
"image",
".",
"attach_grad",
"(",
")",
"Conv2D",
".",
"capture_layer_name",... | This is an internal helper function that can be used for either of these
but not both at the same time:
1. Record the output and gradient of output of an intermediate convolutional layer.
2. Record the gradients of the image.
Parameters
----------
image : NDArray
Image to visuaize. This... | [
"This",
"is",
"an",
"internal",
"helper",
"function",
"that",
"can",
"be",
"used",
"for",
"either",
"of",
"these",
"but",
"not",
"both",
"at",
"the",
"same",
"time",
":",
"1",
".",
"Record",
"the",
"output",
"and",
"gradient",
"of",
"output",
"of",
"an... | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/docs/tutorial_utils/vision/cnn_visualization/gradcam.py#L122-L167 | train |
apache/incubator-mxnet | docs/tutorial_utils/vision/cnn_visualization/gradcam.py | get_conv_out_grad | def get_conv_out_grad(net, image, class_id=None, conv_layer_name=None):
"""Get the output and gradients of output of a convolutional layer.
Parameters:
----------
net: Block
Network to use for visualization.
image: NDArray
Preprocessed image to use for visualization.
class_id: i... | python | def get_conv_out_grad(net, image, class_id=None, conv_layer_name=None):
"""Get the output and gradients of output of a convolutional layer.
Parameters:
----------
net: Block
Network to use for visualization.
image: NDArray
Preprocessed image to use for visualization.
class_id: i... | [
"def",
"get_conv_out_grad",
"(",
"net",
",",
"image",
",",
"class_id",
"=",
"None",
",",
"conv_layer_name",
"=",
"None",
")",
":",
"return",
"_get_grad",
"(",
"net",
",",
"image",
",",
"class_id",
",",
"conv_layer_name",
",",
"image_grad",
"=",
"False",
")... | Get the output and gradients of output of a convolutional layer.
Parameters:
----------
net: Block
Network to use for visualization.
image: NDArray
Preprocessed image to use for visualization.
class_id: int
Category ID this image belongs to. If not provided,
network'... | [
"Get",
"the",
"output",
"and",
"gradients",
"of",
"output",
"of",
"a",
"convolutional",
"layer",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/docs/tutorial_utils/vision/cnn_visualization/gradcam.py#L169-L183 | train |
apache/incubator-mxnet | docs/tutorial_utils/vision/cnn_visualization/gradcam.py | get_image_grad | def get_image_grad(net, image, class_id=None):
"""Get the gradients of the image.
Parameters:
----------
net: Block
Network to use for visualization.
image: NDArray
Preprocessed image to use for visualization.
class_id: int
Category ID this image belongs to. If not provi... | python | def get_image_grad(net, image, class_id=None):
"""Get the gradients of the image.
Parameters:
----------
net: Block
Network to use for visualization.
image: NDArray
Preprocessed image to use for visualization.
class_id: int
Category ID this image belongs to. If not provi... | [
"def",
"get_image_grad",
"(",
"net",
",",
"image",
",",
"class_id",
"=",
"None",
")",
":",
"return",
"_get_grad",
"(",
"net",
",",
"image",
",",
"class_id",
",",
"image_grad",
"=",
"True",
")"
] | Get the gradients of the image.
Parameters:
----------
net: Block
Network to use for visualization.
image: NDArray
Preprocessed image to use for visualization.
class_id: int
Category ID this image belongs to. If not provided,
network's prediction will be used. | [
"Get",
"the",
"gradients",
"of",
"the",
"image",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/docs/tutorial_utils/vision/cnn_visualization/gradcam.py#L185-L197 | train |
apache/incubator-mxnet | docs/tutorial_utils/vision/cnn_visualization/gradcam.py | grad_to_image | def grad_to_image(gradient):
"""Convert gradients of image obtained using `get_image_grad`
into image. This shows parts of the image that is most strongly activating
the output neurons."""
gradient = gradient - gradient.min()
gradient /= gradient.max()
gradient = np.uint8(gradient * 255).transpo... | python | def grad_to_image(gradient):
"""Convert gradients of image obtained using `get_image_grad`
into image. This shows parts of the image that is most strongly activating
the output neurons."""
gradient = gradient - gradient.min()
gradient /= gradient.max()
gradient = np.uint8(gradient * 255).transpo... | [
"def",
"grad_to_image",
"(",
"gradient",
")",
":",
"gradient",
"=",
"gradient",
"-",
"gradient",
".",
"min",
"(",
")",
"gradient",
"/=",
"gradient",
".",
"max",
"(",
")",
"gradient",
"=",
"np",
".",
"uint8",
"(",
"gradient",
"*",
"255",
")",
".",
"tr... | Convert gradients of image obtained using `get_image_grad`
into image. This shows parts of the image that is most strongly activating
the output neurons. | [
"Convert",
"gradients",
"of",
"image",
"obtained",
"using",
"get_image_grad",
"into",
"image",
".",
"This",
"shows",
"parts",
"of",
"the",
"image",
"that",
"is",
"most",
"strongly",
"activating",
"the",
"output",
"neurons",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/docs/tutorial_utils/vision/cnn_visualization/gradcam.py#L199-L207 | train |
apache/incubator-mxnet | docs/tutorial_utils/vision/cnn_visualization/gradcam.py | get_cam | def get_cam(imggrad, conv_out):
"""Compute CAM. Refer section 3 of https://arxiv.org/abs/1610.02391 for details"""
weights = np.mean(imggrad, axis=(1, 2))
cam = np.ones(conv_out.shape[1:], dtype=np.float32)
for i, w in enumerate(weights):
cam += w * conv_out[i, :, :]
cam = cv2.resize(cam, (i... | python | def get_cam(imggrad, conv_out):
"""Compute CAM. Refer section 3 of https://arxiv.org/abs/1610.02391 for details"""
weights = np.mean(imggrad, axis=(1, 2))
cam = np.ones(conv_out.shape[1:], dtype=np.float32)
for i, w in enumerate(weights):
cam += w * conv_out[i, :, :]
cam = cv2.resize(cam, (i... | [
"def",
"get_cam",
"(",
"imggrad",
",",
"conv_out",
")",
":",
"weights",
"=",
"np",
".",
"mean",
"(",
"imggrad",
",",
"axis",
"=",
"(",
"1",
",",
"2",
")",
")",
"cam",
"=",
"np",
".",
"ones",
"(",
"conv_out",
".",
"shape",
"[",
"1",
":",
"]",
... | Compute CAM. Refer section 3 of https://arxiv.org/abs/1610.02391 for details | [
"Compute",
"CAM",
".",
"Refer",
"section",
"3",
"of",
"https",
":",
"//",
"arxiv",
".",
"org",
"/",
"abs",
"/",
"1610",
".",
"02391",
"for",
"details"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/docs/tutorial_utils/vision/cnn_visualization/gradcam.py#L209-L219 | train |
apache/incubator-mxnet | docs/tutorial_utils/vision/cnn_visualization/gradcam.py | get_img_heatmap | def get_img_heatmap(orig_img, activation_map):
"""Draw a heatmap on top of the original image using intensities from activation_map"""
heatmap = cv2.applyColorMap(activation_map, cv2.COLORMAP_COOL)
heatmap = cv2.cvtColor(heatmap, cv2.COLOR_BGR2RGB)
img_heatmap = np.float32(heatmap) + np.float32(orig_img... | python | def get_img_heatmap(orig_img, activation_map):
"""Draw a heatmap on top of the original image using intensities from activation_map"""
heatmap = cv2.applyColorMap(activation_map, cv2.COLORMAP_COOL)
heatmap = cv2.cvtColor(heatmap, cv2.COLOR_BGR2RGB)
img_heatmap = np.float32(heatmap) + np.float32(orig_img... | [
"def",
"get_img_heatmap",
"(",
"orig_img",
",",
"activation_map",
")",
":",
"heatmap",
"=",
"cv2",
".",
"applyColorMap",
"(",
"activation_map",
",",
"cv2",
".",
"COLORMAP_COOL",
")",
"heatmap",
"=",
"cv2",
".",
"cvtColor",
"(",
"heatmap",
",",
"cv2",
".",
... | Draw a heatmap on top of the original image using intensities from activation_map | [
"Draw",
"a",
"heatmap",
"on",
"top",
"of",
"the",
"original",
"image",
"using",
"intensities",
"from",
"activation_map"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/docs/tutorial_utils/vision/cnn_visualization/gradcam.py#L225-L232 | train |
apache/incubator-mxnet | docs/tutorial_utils/vision/cnn_visualization/gradcam.py | to_grayscale | def to_grayscale(cv2im):
"""Convert gradients to grayscale. This gives a saliency map."""
# How strongly does each position activate the output
grayscale_im = np.sum(np.abs(cv2im), axis=0)
# Normalize between min and 99th percentile
im_max = np.percentile(grayscale_im, 99)
im_min = np.min(grays... | python | def to_grayscale(cv2im):
"""Convert gradients to grayscale. This gives a saliency map."""
# How strongly does each position activate the output
grayscale_im = np.sum(np.abs(cv2im), axis=0)
# Normalize between min and 99th percentile
im_max = np.percentile(grayscale_im, 99)
im_min = np.min(grays... | [
"def",
"to_grayscale",
"(",
"cv2im",
")",
":",
"# How strongly does each position activate the output",
"grayscale_im",
"=",
"np",
".",
"sum",
"(",
"np",
".",
"abs",
"(",
"cv2im",
")",
",",
"axis",
"=",
"0",
")",
"# Normalize between min and 99th percentile",
"im_ma... | Convert gradients to grayscale. This gives a saliency map. | [
"Convert",
"gradients",
"to",
"grayscale",
".",
"This",
"gives",
"a",
"saliency",
"map",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/docs/tutorial_utils/vision/cnn_visualization/gradcam.py#L234-L245 | train |
apache/incubator-mxnet | python/mxnet/metric.py | check_label_shapes | def check_label_shapes(labels, preds, wrap=False, shape=False):
"""Helper function for checking shape of label and prediction
Parameters
----------
labels : list of `NDArray`
The labels of the data.
preds : list of `NDArray`
Predicted values.
wrap : boolean
If True, wr... | python | def check_label_shapes(labels, preds, wrap=False, shape=False):
"""Helper function for checking shape of label and prediction
Parameters
----------
labels : list of `NDArray`
The labels of the data.
preds : list of `NDArray`
Predicted values.
wrap : boolean
If True, wr... | [
"def",
"check_label_shapes",
"(",
"labels",
",",
"preds",
",",
"wrap",
"=",
"False",
",",
"shape",
"=",
"False",
")",
":",
"if",
"not",
"shape",
":",
"label_shape",
",",
"pred_shape",
"=",
"len",
"(",
"labels",
")",
",",
"len",
"(",
"preds",
")",
"el... | Helper function for checking shape of label and prediction
Parameters
----------
labels : list of `NDArray`
The labels of the data.
preds : list of `NDArray`
Predicted values.
wrap : boolean
If True, wrap labels/preds in a list if they are single NDArray
shape : boole... | [
"Helper",
"function",
"for",
"checking",
"shape",
"of",
"label",
"and",
"prediction"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/metric.py#L33-L66 | train |
apache/incubator-mxnet | python/mxnet/metric.py | create | def create(metric, *args, **kwargs):
"""Creates evaluation metric from metric names or instances of EvalMetric
or a custom metric function.
Parameters
----------
metric : str or callable
Specifies the metric to create.
This argument must be one of the below:
- Name of a met... | python | def create(metric, *args, **kwargs):
"""Creates evaluation metric from metric names or instances of EvalMetric
or a custom metric function.
Parameters
----------
metric : str or callable
Specifies the metric to create.
This argument must be one of the below:
- Name of a met... | [
"def",
"create",
"(",
"metric",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"callable",
"(",
"metric",
")",
":",
"return",
"CustomMetric",
"(",
"metric",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"elif",
"isinstance",
"(",
"met... | Creates evaluation metric from metric names or instances of EvalMetric
or a custom metric function.
Parameters
----------
metric : str or callable
Specifies the metric to create.
This argument must be one of the below:
- Name of a metric.
- An instance of `EvalMetric`.
... | [
"Creates",
"evaluation",
"metric",
"from",
"metric",
"names",
"or",
"instances",
"of",
"EvalMetric",
"or",
"a",
"custom",
"metric",
"function",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/metric.py#L234-L273 | train |
apache/incubator-mxnet | python/mxnet/metric.py | np | def np(numpy_feval, name=None, allow_extra_outputs=False):
"""Creates a custom evaluation metric that receives its inputs as numpy arrays.
Parameters
----------
numpy_feval : callable(label, pred)
Custom evaluation function that receives labels and predictions for a minibatch
as numpy a... | python | def np(numpy_feval, name=None, allow_extra_outputs=False):
"""Creates a custom evaluation metric that receives its inputs as numpy arrays.
Parameters
----------
numpy_feval : callable(label, pred)
Custom evaluation function that receives labels and predictions for a minibatch
as numpy a... | [
"def",
"np",
"(",
"numpy_feval",
",",
"name",
"=",
"None",
",",
"allow_extra_outputs",
"=",
"False",
")",
":",
"def",
"feval",
"(",
"label",
",",
"pred",
")",
":",
"\"\"\"Internal eval function.\"\"\"",
"return",
"numpy_feval",
"(",
"label",
",",
"pred",
")"... | Creates a custom evaluation metric that receives its inputs as numpy arrays.
Parameters
----------
numpy_feval : callable(label, pred)
Custom evaluation function that receives labels and predictions for a minibatch
as numpy arrays and returns the corresponding custom metric as a floating po... | [
"Creates",
"a",
"custom",
"evaluation",
"metric",
"that",
"receives",
"its",
"inputs",
"as",
"numpy",
"arrays",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/metric.py#L1747-L1778 | train |
apache/incubator-mxnet | python/mxnet/metric.py | EvalMetric.get_config | def get_config(self):
"""Save configurations of metric. Can be recreated
from configs with metric.create(``**config``)
"""
config = self._kwargs.copy()
config.update({
'metric': self.__class__.__name__,
'name': self.name,
'output_names': self.o... | python | def get_config(self):
"""Save configurations of metric. Can be recreated
from configs with metric.create(``**config``)
"""
config = self._kwargs.copy()
config.update({
'metric': self.__class__.__name__,
'name': self.name,
'output_names': self.o... | [
"def",
"get_config",
"(",
"self",
")",
":",
"config",
"=",
"self",
".",
"_kwargs",
".",
"copy",
"(",
")",
"config",
".",
"update",
"(",
"{",
"'metric'",
":",
"self",
".",
"__class__",
".",
"__name__",
",",
"'name'",
":",
"self",
".",
"name",
",",
"... | Save configurations of metric. Can be recreated
from configs with metric.create(``**config``) | [
"Save",
"configurations",
"of",
"metric",
".",
"Can",
"be",
"recreated",
"from",
"configs",
"with",
"metric",
".",
"create",
"(",
"**",
"config",
")"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/metric.py#L100-L110 | train |
apache/incubator-mxnet | python/mxnet/metric.py | EvalMetric.update_dict | def update_dict(self, label, pred):
"""Update the internal evaluation with named label and pred
Parameters
----------
labels : OrderedDict of str -> NDArray
name to array mapping for labels.
preds : OrderedDict of str -> NDArray
name to array mapping of ... | python | def update_dict(self, label, pred):
"""Update the internal evaluation with named label and pred
Parameters
----------
labels : OrderedDict of str -> NDArray
name to array mapping for labels.
preds : OrderedDict of str -> NDArray
name to array mapping of ... | [
"def",
"update_dict",
"(",
"self",
",",
"label",
",",
"pred",
")",
":",
"if",
"self",
".",
"output_names",
"is",
"not",
"None",
":",
"pred",
"=",
"[",
"pred",
"[",
"name",
"]",
"for",
"name",
"in",
"self",
".",
"output_names",
"]",
"else",
":",
"pr... | Update the internal evaluation with named label and pred
Parameters
----------
labels : OrderedDict of str -> NDArray
name to array mapping for labels.
preds : OrderedDict of str -> NDArray
name to array mapping of predicted outputs. | [
"Update",
"the",
"internal",
"evaluation",
"with",
"named",
"label",
"and",
"pred"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/metric.py#L112-L133 | train |
apache/incubator-mxnet | python/mxnet/metric.py | EvalMetric.reset | def reset(self):
"""Resets the internal evaluation result to initial state."""
self.num_inst = 0
self.sum_metric = 0.0
self.global_num_inst = 0
self.global_sum_metric = 0.0 | python | def reset(self):
"""Resets the internal evaluation result to initial state."""
self.num_inst = 0
self.sum_metric = 0.0
self.global_num_inst = 0
self.global_sum_metric = 0.0 | [
"def",
"reset",
"(",
"self",
")",
":",
"self",
".",
"num_inst",
"=",
"0",
"self",
".",
"sum_metric",
"=",
"0.0",
"self",
".",
"global_num_inst",
"=",
"0",
"self",
".",
"global_sum_metric",
"=",
"0.0"
] | Resets the internal evaluation result to initial state. | [
"Resets",
"the",
"internal",
"evaluation",
"result",
"to",
"initial",
"state",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/metric.py#L148-L153 | train |
apache/incubator-mxnet | python/mxnet/metric.py | EvalMetric.get | def get(self):
"""Gets the current evaluation result.
Returns
-------
names : list of str
Name of the metrics.
values : list of float
Value of the evaluations.
"""
if self.num_inst == 0:
return (self.name, float('nan'))
e... | python | def get(self):
"""Gets the current evaluation result.
Returns
-------
names : list of str
Name of the metrics.
values : list of float
Value of the evaluations.
"""
if self.num_inst == 0:
return (self.name, float('nan'))
e... | [
"def",
"get",
"(",
"self",
")",
":",
"if",
"self",
".",
"num_inst",
"==",
"0",
":",
"return",
"(",
"self",
".",
"name",
",",
"float",
"(",
"'nan'",
")",
")",
"else",
":",
"return",
"(",
"self",
".",
"name",
",",
"self",
".",
"sum_metric",
"/",
... | Gets the current evaluation result.
Returns
-------
names : list of str
Name of the metrics.
values : list of float
Value of the evaluations. | [
"Gets",
"the",
"current",
"evaluation",
"result",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/metric.py#L161-L174 | train |
apache/incubator-mxnet | python/mxnet/metric.py | EvalMetric.get_global | def get_global(self):
"""Gets the current global evaluation result.
Returns
-------
names : list of str
Name of the metrics.
values : list of float
Value of the evaluations.
"""
if self._has_global_stats:
if self.global_num_inst ... | python | def get_global(self):
"""Gets the current global evaluation result.
Returns
-------
names : list of str
Name of the metrics.
values : list of float
Value of the evaluations.
"""
if self._has_global_stats:
if self.global_num_inst ... | [
"def",
"get_global",
"(",
"self",
")",
":",
"if",
"self",
".",
"_has_global_stats",
":",
"if",
"self",
".",
"global_num_inst",
"==",
"0",
":",
"return",
"(",
"self",
".",
"name",
",",
"float",
"(",
"'nan'",
")",
")",
"else",
":",
"return",
"(",
"self... | Gets the current global evaluation result.
Returns
-------
names : list of str
Name of the metrics.
values : list of float
Value of the evaluations. | [
"Gets",
"the",
"current",
"global",
"evaluation",
"result",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/metric.py#L176-L192 | train |
apache/incubator-mxnet | python/mxnet/metric.py | EvalMetric.get_name_value | def get_name_value(self):
"""Returns zipped name and value pairs.
Returns
-------
list of tuples
A (name, value) tuple list.
"""
name, value = self.get()
if not isinstance(name, list):
name = [name]
if not isinstance(value, list):
... | python | def get_name_value(self):
"""Returns zipped name and value pairs.
Returns
-------
list of tuples
A (name, value) tuple list.
"""
name, value = self.get()
if not isinstance(name, list):
name = [name]
if not isinstance(value, list):
... | [
"def",
"get_name_value",
"(",
"self",
")",
":",
"name",
",",
"value",
"=",
"self",
".",
"get",
"(",
")",
"if",
"not",
"isinstance",
"(",
"name",
",",
"list",
")",
":",
"name",
"=",
"[",
"name",
"]",
"if",
"not",
"isinstance",
"(",
"value",
",",
"... | Returns zipped name and value pairs.
Returns
-------
list of tuples
A (name, value) tuple list. | [
"Returns",
"zipped",
"name",
"and",
"value",
"pairs",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/metric.py#L194-L207 | train |
apache/incubator-mxnet | python/mxnet/metric.py | EvalMetric.get_global_name_value | def get_global_name_value(self):
"""Returns zipped name and value pairs for global results.
Returns
-------
list of tuples
A (name, value) tuple list.
"""
if self._has_global_stats:
name, value = self.get_global()
if not isinstance(nam... | python | def get_global_name_value(self):
"""Returns zipped name and value pairs for global results.
Returns
-------
list of tuples
A (name, value) tuple list.
"""
if self._has_global_stats:
name, value = self.get_global()
if not isinstance(nam... | [
"def",
"get_global_name_value",
"(",
"self",
")",
":",
"if",
"self",
".",
"_has_global_stats",
":",
"name",
",",
"value",
"=",
"self",
".",
"get_global",
"(",
")",
"if",
"not",
"isinstance",
"(",
"name",
",",
"list",
")",
":",
"name",
"=",
"[",
"name",... | Returns zipped name and value pairs for global results.
Returns
-------
list of tuples
A (name, value) tuple list. | [
"Returns",
"zipped",
"name",
"and",
"value",
"pairs",
"for",
"global",
"results",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/metric.py#L209-L225 | train |
apache/incubator-mxnet | python/mxnet/metric.py | _BinaryClassificationMetrics.update_binary_stats | def update_binary_stats(self, label, pred):
"""
Update various binary classification counts for a single (label, pred)
pair.
Parameters
----------
label : `NDArray`
The labels of the data.
pred : `NDArray`
Predicted values.
"""
... | python | def update_binary_stats(self, label, pred):
"""
Update various binary classification counts for a single (label, pred)
pair.
Parameters
----------
label : `NDArray`
The labels of the data.
pred : `NDArray`
Predicted values.
"""
... | [
"def",
"update_binary_stats",
"(",
"self",
",",
"label",
",",
"pred",
")",
":",
"pred",
"=",
"pred",
".",
"asnumpy",
"(",
")",
"label",
"=",
"label",
".",
"asnumpy",
"(",
")",
".",
"astype",
"(",
"'int32'",
")",
"pred_label",
"=",
"numpy",
".",
"argm... | Update various binary classification counts for a single (label, pred)
pair.
Parameters
----------
label : `NDArray`
The labels of the data.
pred : `NDArray`
Predicted values. | [
"Update",
"various",
"binary",
"classification",
"counts",
"for",
"a",
"single",
"(",
"label",
"pred",
")",
"pair",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/metric.py#L612-L649 | train |
apache/incubator-mxnet | python/mxnet/metric.py | _BinaryClassificationMetrics.matthewscc | def matthewscc(self, use_global=False):
"""
Calculate the Matthew's Correlation Coefficent
"""
if use_global:
if not self.global_total_examples:
return 0.
true_pos = float(self.global_true_positives)
false_pos = float(self.global_false... | python | def matthewscc(self, use_global=False):
"""
Calculate the Matthew's Correlation Coefficent
"""
if use_global:
if not self.global_total_examples:
return 0.
true_pos = float(self.global_true_positives)
false_pos = float(self.global_false... | [
"def",
"matthewscc",
"(",
"self",
",",
"use_global",
"=",
"False",
")",
":",
"if",
"use_global",
":",
"if",
"not",
"self",
".",
"global_total_examples",
":",
"return",
"0.",
"true_pos",
"=",
"float",
"(",
"self",
".",
"global_true_positives",
")",
"false_pos... | Calculate the Matthew's Correlation Coefficent | [
"Calculate",
"the",
"Matthew",
"s",
"Correlation",
"Coefficent"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/metric.py#L693-L721 | train |
apache/incubator-mxnet | python/mxnet/gluon/data/dataset.py | Dataset.transform | def transform(self, fn, lazy=True):
"""Returns a new dataset with each sample transformed by the
transformer function `fn`.
Parameters
----------
fn : callable
A transformer function that takes a sample as input and
returns the transformed sample.
... | python | def transform(self, fn, lazy=True):
"""Returns a new dataset with each sample transformed by the
transformer function `fn`.
Parameters
----------
fn : callable
A transformer function that takes a sample as input and
returns the transformed sample.
... | [
"def",
"transform",
"(",
"self",
",",
"fn",
",",
"lazy",
"=",
"True",
")",
":",
"trans",
"=",
"_LazyTransformDataset",
"(",
"self",
",",
"fn",
")",
"if",
"lazy",
":",
"return",
"trans",
"return",
"SimpleDataset",
"(",
"[",
"i",
"for",
"i",
"in",
"tra... | Returns a new dataset with each sample transformed by the
transformer function `fn`.
Parameters
----------
fn : callable
A transformer function that takes a sample as input and
returns the transformed sample.
lazy : bool, default True
If False... | [
"Returns",
"a",
"new",
"dataset",
"with",
"each",
"sample",
"transformed",
"by",
"the",
"transformer",
"function",
"fn",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/gluon/data/dataset.py#L43-L66 | train |
apache/incubator-mxnet | python/mxnet/gluon/data/dataset.py | Dataset.transform_first | def transform_first(self, fn, lazy=True):
"""Returns a new dataset with the first element of each sample
transformed by the transformer function `fn`.
This is useful, for example, when you only want to transform data
while keeping label as is.
Parameters
----------
... | python | def transform_first(self, fn, lazy=True):
"""Returns a new dataset with the first element of each sample
transformed by the transformer function `fn`.
This is useful, for example, when you only want to transform data
while keeping label as is.
Parameters
----------
... | [
"def",
"transform_first",
"(",
"self",
",",
"fn",
",",
"lazy",
"=",
"True",
")",
":",
"return",
"self",
".",
"transform",
"(",
"_TransformFirstClosure",
"(",
"fn",
")",
",",
"lazy",
")"
] | Returns a new dataset with the first element of each sample
transformed by the transformer function `fn`.
This is useful, for example, when you only want to transform data
while keeping label as is.
Parameters
----------
fn : callable
A transformer function ... | [
"Returns",
"a",
"new",
"dataset",
"with",
"the",
"first",
"element",
"of",
"each",
"sample",
"transformed",
"by",
"the",
"transformer",
"function",
"fn",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/gluon/data/dataset.py#L68-L91 | train |
apache/incubator-mxnet | example/ctc/ocr_predict.py | lstm_ocr_model.forward_ocr | def forward_ocr(self, img_):
"""Forward the image through the LSTM network model
Parameters
----------
img_: int of array
Returns
----------
label_list: string of list
"""
img_ = cv2.resize(img_, (80, 30))
img_ = img_.transpose(1, 0)
... | python | def forward_ocr(self, img_):
"""Forward the image through the LSTM network model
Parameters
----------
img_: int of array
Returns
----------
label_list: string of list
"""
img_ = cv2.resize(img_, (80, 30))
img_ = img_.transpose(1, 0)
... | [
"def",
"forward_ocr",
"(",
"self",
",",
"img_",
")",
":",
"img_",
"=",
"cv2",
".",
"resize",
"(",
"img_",
",",
"(",
"80",
",",
"30",
")",
")",
"img_",
"=",
"img_",
".",
"transpose",
"(",
"1",
",",
"0",
")",
"print",
"(",
"img_",
".",
"shape",
... | Forward the image through the LSTM network model
Parameters
----------
img_: int of array
Returns
----------
label_list: string of list | [
"Forward",
"the",
"image",
"through",
"the",
"LSTM",
"network",
"model"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ctc/ocr_predict.py#L63-L88 | train |
apache/incubator-mxnet | tools/caffe_converter/caffe_parser.py | read_prototxt | def read_prototxt(fname):
"""Return a caffe_pb2.NetParameter object that defined in a prototxt file
"""
proto = caffe_pb2.NetParameter()
with open(fname, 'r') as f:
text_format.Merge(str(f.read()), proto)
return proto | python | def read_prototxt(fname):
"""Return a caffe_pb2.NetParameter object that defined in a prototxt file
"""
proto = caffe_pb2.NetParameter()
with open(fname, 'r') as f:
text_format.Merge(str(f.read()), proto)
return proto | [
"def",
"read_prototxt",
"(",
"fname",
")",
":",
"proto",
"=",
"caffe_pb2",
".",
"NetParameter",
"(",
")",
"with",
"open",
"(",
"fname",
",",
"'r'",
")",
"as",
"f",
":",
"text_format",
".",
"Merge",
"(",
"str",
"(",
"f",
".",
"read",
"(",
")",
")",
... | Return a caffe_pb2.NetParameter object that defined in a prototxt file | [
"Return",
"a",
"caffe_pb2",
".",
"NetParameter",
"object",
"that",
"defined",
"in",
"a",
"prototxt",
"file"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/tools/caffe_converter/caffe_parser.py#L34-L40 | train |
apache/incubator-mxnet | tools/caffe_converter/caffe_parser.py | get_layers | def get_layers(proto):
"""Returns layers in a caffe_pb2.NetParameter object
"""
if len(proto.layer):
return proto.layer
elif len(proto.layers):
return proto.layers
else:
raise ValueError('Invalid proto file.') | python | def get_layers(proto):
"""Returns layers in a caffe_pb2.NetParameter object
"""
if len(proto.layer):
return proto.layer
elif len(proto.layers):
return proto.layers
else:
raise ValueError('Invalid proto file.') | [
"def",
"get_layers",
"(",
"proto",
")",
":",
"if",
"len",
"(",
"proto",
".",
"layer",
")",
":",
"return",
"proto",
".",
"layer",
"elif",
"len",
"(",
"proto",
".",
"layers",
")",
":",
"return",
"proto",
".",
"layers",
"else",
":",
"raise",
"ValueError... | Returns layers in a caffe_pb2.NetParameter object | [
"Returns",
"layers",
"in",
"a",
"caffe_pb2",
".",
"NetParameter",
"object"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/tools/caffe_converter/caffe_parser.py#L42-L50 | train |
apache/incubator-mxnet | tools/caffe_converter/caffe_parser.py | read_caffemodel | def read_caffemodel(prototxt_fname, caffemodel_fname):
"""Return a caffe_pb2.NetParameter object that defined in a binary
caffemodel file
"""
if use_caffe:
caffe.set_mode_cpu()
net = caffe.Net(prototxt_fname, caffemodel_fname, caffe.TEST)
layer_names = net._layer_names
la... | python | def read_caffemodel(prototxt_fname, caffemodel_fname):
"""Return a caffe_pb2.NetParameter object that defined in a binary
caffemodel file
"""
if use_caffe:
caffe.set_mode_cpu()
net = caffe.Net(prototxt_fname, caffemodel_fname, caffe.TEST)
layer_names = net._layer_names
la... | [
"def",
"read_caffemodel",
"(",
"prototxt_fname",
",",
"caffemodel_fname",
")",
":",
"if",
"use_caffe",
":",
"caffe",
".",
"set_mode_cpu",
"(",
")",
"net",
"=",
"caffe",
".",
"Net",
"(",
"prototxt_fname",
",",
"caffemodel_fname",
",",
"caffe",
".",
"TEST",
")... | Return a caffe_pb2.NetParameter object that defined in a binary
caffemodel file | [
"Return",
"a",
"caffe_pb2",
".",
"NetParameter",
"object",
"that",
"defined",
"in",
"a",
"binary",
"caffemodel",
"file"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/tools/caffe_converter/caffe_parser.py#L52-L66 | train |
apache/incubator-mxnet | tools/caffe_converter/caffe_parser.py | layer_iter | def layer_iter(layers, layer_names):
"""Iterate over all layers"""
if use_caffe:
for layer_idx, layer in enumerate(layers):
layer_name = re.sub('[-/]', '_', layer_names[layer_idx])
layer_type = layer.type
layer_blobs = layer.blobs
yield (layer_name, layer_... | python | def layer_iter(layers, layer_names):
"""Iterate over all layers"""
if use_caffe:
for layer_idx, layer in enumerate(layers):
layer_name = re.sub('[-/]', '_', layer_names[layer_idx])
layer_type = layer.type
layer_blobs = layer.blobs
yield (layer_name, layer_... | [
"def",
"layer_iter",
"(",
"layers",
",",
"layer_names",
")",
":",
"if",
"use_caffe",
":",
"for",
"layer_idx",
",",
"layer",
"in",
"enumerate",
"(",
"layers",
")",
":",
"layer_name",
"=",
"re",
".",
"sub",
"(",
"'[-/]'",
",",
"'_'",
",",
"layer_names",
... | Iterate over all layers | [
"Iterate",
"over",
"all",
"layers"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/tools/caffe_converter/caffe_parser.py#L68-L81 | train |
apache/incubator-mxnet | python/mxnet/profiler.py | set_config | def set_config(**kwargs):
"""Set up the configure of profiler (only accepts keyword arguments).
Parameters
----------
filename : string,
output file for profile data
profile_all : boolean,
all profile types enabled
profile_symbolic : boolean,
whether to profile symbolic ... | python | def set_config(**kwargs):
"""Set up the configure of profiler (only accepts keyword arguments).
Parameters
----------
filename : string,
output file for profile data
profile_all : boolean,
all profile types enabled
profile_symbolic : boolean,
whether to profile symbolic ... | [
"def",
"set_config",
"(",
"*",
"*",
"kwargs",
")",
":",
"kk",
"=",
"kwargs",
".",
"keys",
"(",
")",
"vv",
"=",
"kwargs",
".",
"values",
"(",
")",
"check_call",
"(",
"_LIB",
".",
"MXSetProcessProfilerConfig",
"(",
"len",
"(",
"kwargs",
")",
",",
"c_st... | Set up the configure of profiler (only accepts keyword arguments).
Parameters
----------
filename : string,
output file for profile data
profile_all : boolean,
all profile types enabled
profile_symbolic : boolean,
whether to profile symbolic operators
profile_imperative ... | [
"Set",
"up",
"the",
"configure",
"of",
"profiler",
"(",
"only",
"accepts",
"keyword",
"arguments",
")",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/profiler.py#L33-L67 | train |
apache/incubator-mxnet | python/mxnet/profiler.py | profiler_set_config | def profiler_set_config(mode='symbolic', filename='profile.json'):
"""Set up the configure of profiler (Deprecated).
Parameters
----------
mode : string, optional
Indicates whether to enable the profiler, can
be 'symbolic', or 'all'. Defaults to `symbolic`.
filename : string, option... | python | def profiler_set_config(mode='symbolic', filename='profile.json'):
"""Set up the configure of profiler (Deprecated).
Parameters
----------
mode : string, optional
Indicates whether to enable the profiler, can
be 'symbolic', or 'all'. Defaults to `symbolic`.
filename : string, option... | [
"def",
"profiler_set_config",
"(",
"mode",
"=",
"'symbolic'",
",",
"filename",
"=",
"'profile.json'",
")",
":",
"warnings",
".",
"warn",
"(",
"'profiler.profiler_set_config() is deprecated. '",
"'Please use profiler.set_config() instead'",
")",
"keys",
"=",
"c_str_array",
... | Set up the configure of profiler (Deprecated).
Parameters
----------
mode : string, optional
Indicates whether to enable the profiler, can
be 'symbolic', or 'all'. Defaults to `symbolic`.
filename : string, optional
The name of output trace file. Defaults to 'profile.json'. | [
"Set",
"up",
"the",
"configure",
"of",
"profiler",
"(",
"Deprecated",
")",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/profiler.py#L70-L86 | train |
apache/incubator-mxnet | python/mxnet/profiler.py | set_state | def set_state(state='stop', profile_process='worker'):
"""Set up the profiler state to 'run' or 'stop'.
Parameters
----------
state : string, optional
Indicates whether to run the profiler, can
be 'stop' or 'run'. Default is `stop`.
profile_process : string
whether to profil... | python | def set_state(state='stop', profile_process='worker'):
"""Set up the profiler state to 'run' or 'stop'.
Parameters
----------
state : string, optional
Indicates whether to run the profiler, can
be 'stop' or 'run'. Default is `stop`.
profile_process : string
whether to profil... | [
"def",
"set_state",
"(",
"state",
"=",
"'stop'",
",",
"profile_process",
"=",
"'worker'",
")",
":",
"state2int",
"=",
"{",
"'stop'",
":",
"0",
",",
"'run'",
":",
"1",
"}",
"profile_process2int",
"=",
"{",
"'worker'",
":",
"0",
",",
"'server'",
":",
"1"... | Set up the profiler state to 'run' or 'stop'.
Parameters
----------
state : string, optional
Indicates whether to run the profiler, can
be 'stop' or 'run'. Default is `stop`.
profile_process : string
whether to profile kvstore `server` or `worker`.
server can only be pro... | [
"Set",
"up",
"the",
"profiler",
"state",
"to",
"run",
"or",
"stop",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/profiler.py#L89-L106 | train |
apache/incubator-mxnet | python/mxnet/profiler.py | dump | def dump(finished=True, profile_process='worker'):
"""Dump profile and stop profiler. Use this to save profile
in advance in case your program cannot exit normally.
Parameters
----------
finished : boolean
Indicates whether to stop statistic output (dumping) after this dump.
Default... | python | def dump(finished=True, profile_process='worker'):
"""Dump profile and stop profiler. Use this to save profile
in advance in case your program cannot exit normally.
Parameters
----------
finished : boolean
Indicates whether to stop statistic output (dumping) after this dump.
Default... | [
"def",
"dump",
"(",
"finished",
"=",
"True",
",",
"profile_process",
"=",
"'worker'",
")",
":",
"fin",
"=",
"1",
"if",
"finished",
"is",
"True",
"else",
"0",
"profile_process2int",
"=",
"{",
"'worker'",
":",
"0",
",",
"'server'",
":",
"1",
"}",
"check_... | Dump profile and stop profiler. Use this to save profile
in advance in case your program cannot exit normally.
Parameters
----------
finished : boolean
Indicates whether to stop statistic output (dumping) after this dump.
Default is True
profile_process : string
whether to p... | [
"Dump",
"profile",
"and",
"stop",
"profiler",
".",
"Use",
"this",
"to",
"save",
"profile",
"in",
"advance",
"in",
"case",
"your",
"program",
"cannot",
"exit",
"normally",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/profiler.py#L122-L140 | train |
apache/incubator-mxnet | python/mxnet/profiler.py | dumps | def dumps(reset=False):
"""Return a printable string of aggregate profile stats.
Parameters
----------
reset: boolean
Indicates whether to clean aggeregate statistical data collected up to this point
"""
debug_str = ctypes.c_char_p()
do_reset = 1 if reset is True else 0
check_ca... | python | def dumps(reset=False):
"""Return a printable string of aggregate profile stats.
Parameters
----------
reset: boolean
Indicates whether to clean aggeregate statistical data collected up to this point
"""
debug_str = ctypes.c_char_p()
do_reset = 1 if reset is True else 0
check_ca... | [
"def",
"dumps",
"(",
"reset",
"=",
"False",
")",
":",
"debug_str",
"=",
"ctypes",
".",
"c_char_p",
"(",
")",
"do_reset",
"=",
"1",
"if",
"reset",
"is",
"True",
"else",
"0",
"check_call",
"(",
"_LIB",
".",
"MXAggregateProfileStatsPrint",
"(",
"ctypes",
".... | Return a printable string of aggregate profile stats.
Parameters
----------
reset: boolean
Indicates whether to clean aggeregate statistical data collected up to this point | [
"Return",
"a",
"printable",
"string",
"of",
"aggregate",
"profile",
"stats",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/profiler.py#L151-L162 | train |
apache/incubator-mxnet | python/mxnet/profiler.py | pause | def pause(profile_process='worker'):
"""Pause profiling.
Parameters
----------
profile_process : string
whether to profile kvstore `server` or `worker`.
server can only be profiled when kvstore is of type dist.
if this is not passed, defaults to `worker`
"""
profile_proc... | python | def pause(profile_process='worker'):
"""Pause profiling.
Parameters
----------
profile_process : string
whether to profile kvstore `server` or `worker`.
server can only be profiled when kvstore is of type dist.
if this is not passed, defaults to `worker`
"""
profile_proc... | [
"def",
"pause",
"(",
"profile_process",
"=",
"'worker'",
")",
":",
"profile_process2int",
"=",
"{",
"'worker'",
":",
"0",
",",
"'server'",
":",
"1",
"}",
"check_call",
"(",
"_LIB",
".",
"MXProcessProfilePause",
"(",
"int",
"(",
"1",
")",
",",
"profile_proc... | Pause profiling.
Parameters
----------
profile_process : string
whether to profile kvstore `server` or `worker`.
server can only be profiled when kvstore is of type dist.
if this is not passed, defaults to `worker` | [
"Pause",
"profiling",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/profiler.py#L165-L178 | train |
apache/incubator-mxnet | python/mxnet/profiler.py | resume | def resume(profile_process='worker'):
"""
Resume paused profiling.
Parameters
----------
profile_process : string
whether to profile kvstore `server` or `worker`.
server can only be profiled when kvstore is of type dist.
if this is not passed, defaults to `worker`
"""
... | python | def resume(profile_process='worker'):
"""
Resume paused profiling.
Parameters
----------
profile_process : string
whether to profile kvstore `server` or `worker`.
server can only be profiled when kvstore is of type dist.
if this is not passed, defaults to `worker`
"""
... | [
"def",
"resume",
"(",
"profile_process",
"=",
"'worker'",
")",
":",
"profile_process2int",
"=",
"{",
"'worker'",
":",
"0",
",",
"'server'",
":",
"1",
"}",
"check_call",
"(",
"_LIB",
".",
"MXProcessProfilePause",
"(",
"int",
"(",
"0",
")",
",",
"profile_pro... | Resume paused profiling.
Parameters
----------
profile_process : string
whether to profile kvstore `server` or `worker`.
server can only be profiled when kvstore is of type dist.
if this is not passed, defaults to `worker` | [
"Resume",
"paused",
"profiling",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/profiler.py#L181-L195 | train |
apache/incubator-mxnet | python/mxnet/profiler.py | Counter.set_value | def set_value(self, value):
"""Set counter value.
Parameters
----------
value : int
Value for the counter
"""
check_call(_LIB.MXProfileSetCounter(self.handle, int(value))) | python | def set_value(self, value):
"""Set counter value.
Parameters
----------
value : int
Value for the counter
"""
check_call(_LIB.MXProfileSetCounter(self.handle, int(value))) | [
"def",
"set_value",
"(",
"self",
",",
"value",
")",
":",
"check_call",
"(",
"_LIB",
".",
"MXProfileSetCounter",
"(",
"self",
".",
"handle",
",",
"int",
"(",
"value",
")",
")",
")"
] | Set counter value.
Parameters
----------
value : int
Value for the counter | [
"Set",
"counter",
"value",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/profiler.py#L405-L413 | train |
apache/incubator-mxnet | python/mxnet/profiler.py | Counter.increment | def increment(self, delta=1):
"""Increment counter value.
Parameters
----------
value_change : int
Amount by which to add to the counter
"""
check_call(_LIB.MXProfileAdjustCounter(self.handle, int(delta))) | python | def increment(self, delta=1):
"""Increment counter value.
Parameters
----------
value_change : int
Amount by which to add to the counter
"""
check_call(_LIB.MXProfileAdjustCounter(self.handle, int(delta))) | [
"def",
"increment",
"(",
"self",
",",
"delta",
"=",
"1",
")",
":",
"check_call",
"(",
"_LIB",
".",
"MXProfileAdjustCounter",
"(",
"self",
".",
"handle",
",",
"int",
"(",
"delta",
")",
")",
")"
] | Increment counter value.
Parameters
----------
value_change : int
Amount by which to add to the counter | [
"Increment",
"counter",
"value",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/profiler.py#L415-L423 | train |
apache/incubator-mxnet | python/mxnet/profiler.py | Counter.decrement | def decrement(self, delta=1):
"""Decrement counter value.
Parameters
----------
value_change : int
Amount by which to subtract from the counter
"""
check_call(_LIB.MXProfileAdjustCounter(self.handle, -int(delta))) | python | def decrement(self, delta=1):
"""Decrement counter value.
Parameters
----------
value_change : int
Amount by which to subtract from the counter
"""
check_call(_LIB.MXProfileAdjustCounter(self.handle, -int(delta))) | [
"def",
"decrement",
"(",
"self",
",",
"delta",
"=",
"1",
")",
":",
"check_call",
"(",
"_LIB",
".",
"MXProfileAdjustCounter",
"(",
"self",
".",
"handle",
",",
"-",
"int",
"(",
"delta",
")",
")",
")"
] | Decrement counter value.
Parameters
----------
value_change : int
Amount by which to subtract from the counter | [
"Decrement",
"counter",
"value",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/profiler.py#L425-L433 | train |
apache/incubator-mxnet | python/mxnet/profiler.py | Marker.mark | def mark(self, scope='process'):
"""Set up the profiler state to record operator.
Parameters
----------
scope : string, optional
Indicates what scope the marker should refer to.
Can be 'global', 'process', thread', task', and 'marker'
Default is `proc... | python | def mark(self, scope='process'):
"""Set up the profiler state to record operator.
Parameters
----------
scope : string, optional
Indicates what scope the marker should refer to.
Can be 'global', 'process', thread', task', and 'marker'
Default is `proc... | [
"def",
"mark",
"(",
"self",
",",
"scope",
"=",
"'process'",
")",
":",
"check_call",
"(",
"_LIB",
".",
"MXProfileSetMarker",
"(",
"self",
".",
"domain",
".",
"handle",
",",
"c_str",
"(",
"self",
".",
"name",
")",
",",
"c_str",
"(",
"scope",
")",
")",
... | Set up the profiler state to record operator.
Parameters
----------
scope : string, optional
Indicates what scope the marker should refer to.
Can be 'global', 'process', thread', task', and 'marker'
Default is `process`. | [
"Set",
"up",
"the",
"profiler",
"state",
"to",
"record",
"operator",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/profiler.py#L463-L473 | train |
apache/incubator-mxnet | python/mxnet/rtc.py | CudaModule.get_kernel | def get_kernel(self, name, signature):
r"""Get CUDA kernel from compiled module.
Parameters
----------
name : str
String name of the kernel.
signature : str
Function signature for the kernel. For example, if a kernel is
declared as::
... | python | def get_kernel(self, name, signature):
r"""Get CUDA kernel from compiled module.
Parameters
----------
name : str
String name of the kernel.
signature : str
Function signature for the kernel. For example, if a kernel is
declared as::
... | [
"def",
"get_kernel",
"(",
"self",
",",
"name",
",",
"signature",
")",
":",
"hdl",
"=",
"CudaKernelHandle",
"(",
")",
"is_ndarray",
"=",
"[",
"]",
"is_const",
"=",
"[",
"]",
"dtypes",
"=",
"[",
"]",
"pattern",
"=",
"re",
".",
"compile",
"(",
"r\"\"\"^... | r"""Get CUDA kernel from compiled module.
Parameters
----------
name : str
String name of the kernel.
signature : str
Function signature for the kernel. For example, if a kernel is
declared as::
extern "C" __global__ void axpy(const f... | [
"r",
"Get",
"CUDA",
"kernel",
"from",
"compiled",
"module",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/rtc.py#L112-L171 | train |
apache/incubator-mxnet | python/mxnet/rtc.py | CudaKernel.launch | def launch(self, args, ctx, grid_dims, block_dims, shared_mem=0):
"""Launch cuda kernel.
Parameters
----------
args : tuple of NDArray or numbers
List of arguments for kernel. NDArrays are expected for pointer
types (e.g. `float*`, `double*`) while numbers are ex... | python | def launch(self, args, ctx, grid_dims, block_dims, shared_mem=0):
"""Launch cuda kernel.
Parameters
----------
args : tuple of NDArray or numbers
List of arguments for kernel. NDArrays are expected for pointer
types (e.g. `float*`, `double*`) while numbers are ex... | [
"def",
"launch",
"(",
"self",
",",
"args",
",",
"ctx",
",",
"grid_dims",
",",
"block_dims",
",",
"shared_mem",
"=",
"0",
")",
":",
"assert",
"ctx",
".",
"device_type",
"==",
"'gpu'",
",",
"\"Cuda kernel can only be launched on GPU\"",
"assert",
"len",
"(",
"... | Launch cuda kernel.
Parameters
----------
args : tuple of NDArray or numbers
List of arguments for kernel. NDArrays are expected for pointer
types (e.g. `float*`, `double*`) while numbers are expected for
non-pointer types (e.g. `int`, `float`).
ctx :... | [
"Launch",
"cuda",
"kernel",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/rtc.py#L185-L230 | train |
apache/incubator-mxnet | example/ssd/evaluate/eval_metric.py | MApMetric.reset | def reset(self):
"""Clear the internal statistics to initial state."""
if getattr(self, 'num', None) is None:
self.num_inst = 0
self.sum_metric = 0.0
else:
self.num_inst = [0] * self.num
self.sum_metric = [0.0] * self.num
self.records = dic... | python | def reset(self):
"""Clear the internal statistics to initial state."""
if getattr(self, 'num', None) is None:
self.num_inst = 0
self.sum_metric = 0.0
else:
self.num_inst = [0] * self.num
self.sum_metric = [0.0] * self.num
self.records = dic... | [
"def",
"reset",
"(",
"self",
")",
":",
"if",
"getattr",
"(",
"self",
",",
"'num'",
",",
"None",
")",
"is",
"None",
":",
"self",
".",
"num_inst",
"=",
"0",
"self",
".",
"sum_metric",
"=",
"0.0",
"else",
":",
"self",
".",
"num_inst",
"=",
"[",
"0",... | Clear the internal statistics to initial state. | [
"Clear",
"the",
"internal",
"statistics",
"to",
"initial",
"state",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/evaluate/eval_metric.py#L53-L62 | train |
apache/incubator-mxnet | example/ssd/evaluate/eval_metric.py | MApMetric.update | def update(self, labels, preds):
"""
Update internal records. This function now only update internal buffer,
sum_metric and num_inst are updated in _update() function instead when
get() is called to return results.
Params:
----------
labels: mx.nd.array (n * 6) o... | python | def update(self, labels, preds):
"""
Update internal records. This function now only update internal buffer,
sum_metric and num_inst are updated in _update() function instead when
get() is called to return results.
Params:
----------
labels: mx.nd.array (n * 6) o... | [
"def",
"update",
"(",
"self",
",",
"labels",
",",
"preds",
")",
":",
"def",
"iou",
"(",
"x",
",",
"ys",
")",
":",
"\"\"\"\n Calculate intersection-over-union overlap\n Params:\n ----------\n x : numpy.array\n single box [... | Update internal records. This function now only update internal buffer,
sum_metric and num_inst are updated in _update() function instead when
get() is called to return results.
Params:
----------
labels: mx.nd.array (n * 6) or (n * 5), difficult column is optional
2... | [
"Update",
"internal",
"records",
".",
"This",
"function",
"now",
"only",
"update",
"internal",
"buffer",
"sum_metric",
"and",
"num_inst",
"are",
"updated",
"in",
"_update",
"()",
"function",
"instead",
"when",
"get",
"()",
"is",
"called",
"to",
"return",
"resu... | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/evaluate/eval_metric.py#L86-L195 | train |
apache/incubator-mxnet | example/ssd/evaluate/eval_metric.py | MApMetric._update | def _update(self):
""" update num_inst and sum_metric """
aps = []
for k, v in self.records.items():
recall, prec = self._recall_prec(v, self.counts[k])
ap = self._average_precision(recall, prec)
aps.append(ap)
if self.num is not None and k < (self... | python | def _update(self):
""" update num_inst and sum_metric """
aps = []
for k, v in self.records.items():
recall, prec = self._recall_prec(v, self.counts[k])
ap = self._average_precision(recall, prec)
aps.append(ap)
if self.num is not None and k < (self... | [
"def",
"_update",
"(",
"self",
")",
":",
"aps",
"=",
"[",
"]",
"for",
"k",
",",
"v",
"in",
"self",
".",
"records",
".",
"items",
"(",
")",
":",
"recall",
",",
"prec",
"=",
"self",
".",
"_recall_prec",
"(",
"v",
",",
"self",
".",
"counts",
"[",
... | update num_inst and sum_metric | [
"update",
"num_inst",
"and",
"sum_metric"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/evaluate/eval_metric.py#L197-L212 | train |
apache/incubator-mxnet | example/ssd/evaluate/eval_metric.py | MApMetric._recall_prec | def _recall_prec(self, record, count):
""" get recall and precision from internal records """
record = np.delete(record, np.where(record[:, 1].astype(int) == 0)[0], axis=0)
sorted_records = record[record[:,0].argsort()[::-1]]
tp = np.cumsum(sorted_records[:, 1].astype(int) == 1)
... | python | def _recall_prec(self, record, count):
""" get recall and precision from internal records """
record = np.delete(record, np.where(record[:, 1].astype(int) == 0)[0], axis=0)
sorted_records = record[record[:,0].argsort()[::-1]]
tp = np.cumsum(sorted_records[:, 1].astype(int) == 1)
... | [
"def",
"_recall_prec",
"(",
"self",
",",
"record",
",",
"count",
")",
":",
"record",
"=",
"np",
".",
"delete",
"(",
"record",
",",
"np",
".",
"where",
"(",
"record",
"[",
":",
",",
"1",
"]",
".",
"astype",
"(",
"int",
")",
"==",
"0",
")",
"[",
... | get recall and precision from internal records | [
"get",
"recall",
"and",
"precision",
"from",
"internal",
"records"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/evaluate/eval_metric.py#L214-L225 | train |
apache/incubator-mxnet | example/ssd/evaluate/eval_metric.py | MApMetric._average_precision | def _average_precision(self, rec, prec):
"""
calculate average precision
Params:
----------
rec : numpy.array
cumulated recall
prec : numpy.array
cumulated precision
Returns:
----------
ap as float
"""
# app... | python | def _average_precision(self, rec, prec):
"""
calculate average precision
Params:
----------
rec : numpy.array
cumulated recall
prec : numpy.array
cumulated precision
Returns:
----------
ap as float
"""
# app... | [
"def",
"_average_precision",
"(",
"self",
",",
"rec",
",",
"prec",
")",
":",
"# append sentinel values at both ends",
"mrec",
"=",
"np",
".",
"concatenate",
"(",
"(",
"[",
"0.",
"]",
",",
"rec",
",",
"[",
"1.",
"]",
")",
")",
"mpre",
"=",
"np",
".",
... | calculate average precision
Params:
----------
rec : numpy.array
cumulated recall
prec : numpy.array
cumulated precision
Returns:
----------
ap as float | [
"calculate",
"average",
"precision"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/evaluate/eval_metric.py#L227-L254 | train |
apache/incubator-mxnet | example/ssd/evaluate/eval_metric.py | MApMetric._insert | def _insert(self, key, records, count):
""" Insert records according to key """
if key not in self.records:
assert key not in self.counts
self.records[key] = records
self.counts[key] = count
else:
self.records[key] = np.vstack((self.records[key], r... | python | def _insert(self, key, records, count):
""" Insert records according to key """
if key not in self.records:
assert key not in self.counts
self.records[key] = records
self.counts[key] = count
else:
self.records[key] = np.vstack((self.records[key], r... | [
"def",
"_insert",
"(",
"self",
",",
"key",
",",
"records",
",",
"count",
")",
":",
"if",
"key",
"not",
"in",
"self",
".",
"records",
":",
"assert",
"key",
"not",
"in",
"self",
".",
"counts",
"self",
".",
"records",
"[",
"key",
"]",
"=",
"records",
... | Insert records according to key | [
"Insert",
"records",
"according",
"to",
"key"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/evaluate/eval_metric.py#L256-L265 | train |
apache/incubator-mxnet | example/ssd/evaluate/eval_metric.py | VOC07MApMetric._average_precision | def _average_precision(self, rec, prec):
"""
calculate average precision, override the default one,
special 11-point metric
Params:
----------
rec : numpy.array
cumulated recall
prec : numpy.array
cumulated precision
Returns:
... | python | def _average_precision(self, rec, prec):
"""
calculate average precision, override the default one,
special 11-point metric
Params:
----------
rec : numpy.array
cumulated recall
prec : numpy.array
cumulated precision
Returns:
... | [
"def",
"_average_precision",
"(",
"self",
",",
"rec",
",",
"prec",
")",
":",
"ap",
"=",
"0.",
"for",
"t",
"in",
"np",
".",
"arange",
"(",
"0.",
",",
"1.1",
",",
"0.1",
")",
":",
"if",
"np",
".",
"sum",
"(",
"rec",
">=",
"t",
")",
"==",
"0",
... | calculate average precision, override the default one,
special 11-point metric
Params:
----------
rec : numpy.array
cumulated recall
prec : numpy.array
cumulated precision
Returns:
----------
ap as float | [
"calculate",
"average",
"precision",
"override",
"the",
"default",
"one",
"special",
"11",
"-",
"point",
"metric"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/evaluate/eval_metric.py#L273-L295 | train |
apache/incubator-mxnet | example/image-classification/fine-tune.py | get_fine_tune_model | def get_fine_tune_model(symbol, arg_params, num_classes, layer_name, dtype='float32'):
"""
symbol: the pre-trained network symbol
arg_params: the argument parameters of the pre-trained model
num_classes: the number of classes for the fine-tune datasets
layer_name: the layer name before the last full... | python | def get_fine_tune_model(symbol, arg_params, num_classes, layer_name, dtype='float32'):
"""
symbol: the pre-trained network symbol
arg_params: the argument parameters of the pre-trained model
num_classes: the number of classes for the fine-tune datasets
layer_name: the layer name before the last full... | [
"def",
"get_fine_tune_model",
"(",
"symbol",
",",
"arg_params",
",",
"num_classes",
",",
"layer_name",
",",
"dtype",
"=",
"'float32'",
")",
":",
"all_layers",
"=",
"symbol",
".",
"get_internals",
"(",
")",
"net",
"=",
"all_layers",
"[",
"layer_name",
"+",
"'... | symbol: the pre-trained network symbol
arg_params: the argument parameters of the pre-trained model
num_classes: the number of classes for the fine-tune datasets
layer_name: the layer name before the last fully-connected layer | [
"symbol",
":",
"the",
"pre",
"-",
"trained",
"network",
"symbol",
"arg_params",
":",
"the",
"argument",
"parameters",
"of",
"the",
"pre",
"-",
"trained",
"model",
"num_classes",
":",
"the",
"number",
"of",
"classes",
"for",
"the",
"fine",
"-",
"tune",
"dat... | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/image-classification/fine-tune.py#L28-L42 | train |
apache/incubator-mxnet | example/gluon/lipnet/data_loader.py | LipsDataset._list_images | def _list_images(self, root):
"""
Description : generate list for lip images
"""
self.labels = []
self.items = []
valid_unseen_sub_idx = [1, 2, 20, 22]
skip_sub_idx = [21]
if self._mode == 'train':
sub_idx = ['s' + str(i) for i in range(1, 35... | python | def _list_images(self, root):
"""
Description : generate list for lip images
"""
self.labels = []
self.items = []
valid_unseen_sub_idx = [1, 2, 20, 22]
skip_sub_idx = [21]
if self._mode == 'train':
sub_idx = ['s' + str(i) for i in range(1, 35... | [
"def",
"_list_images",
"(",
"self",
",",
"root",
")",
":",
"self",
".",
"labels",
"=",
"[",
"]",
"self",
".",
"items",
"=",
"[",
"]",
"valid_unseen_sub_idx",
"=",
"[",
"1",
",",
"2",
",",
"20",
",",
"22",
"]",
"skip_sub_idx",
"=",
"[",
"21",
"]",... | Description : generate list for lip images | [
"Description",
":",
"generate",
"list",
"for",
"lip",
"images"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/lipnet/data_loader.py#L45-L71 | train |
apache/incubator-mxnet | example/gluon/lipnet/data_loader.py | LipsDataset.align_generation | def align_generation(self, file_nm, padding=75):
"""
Description : Align to lip position
"""
align = Align(self._align_root + '/' + file_nm + '.align')
return nd.array(align.sentence(padding)) | python | def align_generation(self, file_nm, padding=75):
"""
Description : Align to lip position
"""
align = Align(self._align_root + '/' + file_nm + '.align')
return nd.array(align.sentence(padding)) | [
"def",
"align_generation",
"(",
"self",
",",
"file_nm",
",",
"padding",
"=",
"75",
")",
":",
"align",
"=",
"Align",
"(",
"self",
".",
"_align_root",
"+",
"'/'",
"+",
"file_nm",
"+",
"'.align'",
")",
"return",
"nd",
".",
"array",
"(",
"align",
".",
"s... | Description : Align to lip position | [
"Description",
":",
"Align",
"to",
"lip",
"position"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/lipnet/data_loader.py#L73-L78 | train |
apache/incubator-mxnet | python/mxnet/initializer.py | Initializer.set_verbosity | def set_verbosity(self, verbose=False, print_func=None):
"""Switch on/off verbose mode
Parameters
----------
verbose : bool
switch on/off verbose mode
print_func : function
A function that computes statistics of initialized arrays.
Takes an `N... | python | def set_verbosity(self, verbose=False, print_func=None):
"""Switch on/off verbose mode
Parameters
----------
verbose : bool
switch on/off verbose mode
print_func : function
A function that computes statistics of initialized arrays.
Takes an `N... | [
"def",
"set_verbosity",
"(",
"self",
",",
"verbose",
"=",
"False",
",",
"print_func",
"=",
"None",
")",
":",
"self",
".",
"_verbose",
"=",
"verbose",
"if",
"print_func",
"is",
"None",
":",
"def",
"asum_stat",
"(",
"x",
")",
":",
"\"\"\"returns |x|/size(x),... | Switch on/off verbose mode
Parameters
----------
verbose : bool
switch on/off verbose mode
print_func : function
A function that computes statistics of initialized arrays.
Takes an `NDArray` and returns an `str`. Defaults to mean
absolute ... | [
"Switch",
"on",
"/",
"off",
"verbose",
"mode"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/initializer.py#L61-L80 | train |
apache/incubator-mxnet | python/mxnet/initializer.py | Initializer._verbose_print | def _verbose_print(self, desc, init, arr):
"""Internal verbose print function
Parameters
----------
desc : InitDesc or str
name of the array
init : str
initializer pattern
arr : NDArray
initialized array
"""
if self._ve... | python | def _verbose_print(self, desc, init, arr):
"""Internal verbose print function
Parameters
----------
desc : InitDesc or str
name of the array
init : str
initializer pattern
arr : NDArray
initialized array
"""
if self._ve... | [
"def",
"_verbose_print",
"(",
"self",
",",
"desc",
",",
"init",
",",
"arr",
")",
":",
"if",
"self",
".",
"_verbose",
"and",
"self",
".",
"_print_func",
":",
"logging",
".",
"info",
"(",
"'Initialized %s as %s: %s'",
",",
"desc",
",",
"init",
",",
"self",... | Internal verbose print function
Parameters
----------
desc : InitDesc or str
name of the array
init : str
initializer pattern
arr : NDArray
initialized array | [
"Internal",
"verbose",
"print",
"function"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/initializer.py#L82-L95 | train |
apache/incubator-mxnet | python/mxnet/initializer.py | Initializer._legacy_init | def _legacy_init(self, name, arr):
"""Legacy initialization method.
Parameters
----------
name : str
Name of corresponding NDArray.
arr : NDArray
NDArray to be initialized.
"""
warnings.warn(
"\033[91mCalling initializer with ... | python | def _legacy_init(self, name, arr):
"""Legacy initialization method.
Parameters
----------
name : str
Name of corresponding NDArray.
arr : NDArray
NDArray to be initialized.
"""
warnings.warn(
"\033[91mCalling initializer with ... | [
"def",
"_legacy_init",
"(",
"self",
",",
"name",
",",
"arr",
")",
":",
"warnings",
".",
"warn",
"(",
"\"\\033[91mCalling initializer with init(str, NDArray) has been deprecated.\"",
"\"please use init(mx.init.InitDesc(...), NDArray) instead.\\033[0m\"",
",",
"DeprecationWarning",
... | Legacy initialization method.
Parameters
----------
name : str
Name of corresponding NDArray.
arr : NDArray
NDArray to be initialized. | [
"Legacy",
"initialization",
"method",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/initializer.py#L171-L217 | train |
apache/incubator-mxnet | example/ssd/dataset/imdb.py | Imdb.save_imglist | def save_imglist(self, fname=None, root=None, shuffle=False):
"""
save imglist to disk
Parameters:
----------
fname : str
saved filename
"""
def progress_bar(count, total, suffix=''):
import sys
bar_len = 24
filled_... | python | def save_imglist(self, fname=None, root=None, shuffle=False):
"""
save imglist to disk
Parameters:
----------
fname : str
saved filename
"""
def progress_bar(count, total, suffix=''):
import sys
bar_len = 24
filled_... | [
"def",
"save_imglist",
"(",
"self",
",",
"fname",
"=",
"None",
",",
"root",
"=",
"None",
",",
"shuffle",
"=",
"False",
")",
":",
"def",
"progress_bar",
"(",
"count",
",",
"total",
",",
"suffix",
"=",
"''",
")",
":",
"import",
"sys",
"bar_len",
"=",
... | save imglist to disk
Parameters:
----------
fname : str
saved filename | [
"save",
"imglist",
"to",
"disk"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/dataset/imdb.py#L70-L110 | train |
apache/incubator-mxnet | example/ssd/dataset/imdb.py | Imdb._load_class_names | def _load_class_names(self, filename, dirname):
"""
load class names from text file
Parameters:
----------
filename: str
file stores class names
dirname: str
file directory
"""
full_path = osp.join(dirname, filename)
classe... | python | def _load_class_names(self, filename, dirname):
"""
load class names from text file
Parameters:
----------
filename: str
file stores class names
dirname: str
file directory
"""
full_path = osp.join(dirname, filename)
classe... | [
"def",
"_load_class_names",
"(",
"self",
",",
"filename",
",",
"dirname",
")",
":",
"full_path",
"=",
"osp",
".",
"join",
"(",
"dirname",
",",
"filename",
")",
"classes",
"=",
"[",
"]",
"with",
"open",
"(",
"full_path",
",",
"'r'",
")",
"as",
"f",
":... | load class names from text file
Parameters:
----------
filename: str
file stores class names
dirname: str
file directory | [
"load",
"class",
"names",
"from",
"text",
"file"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/dataset/imdb.py#L112-L127 | train |
apache/incubator-mxnet | example/image-classification/train_mnist.py | read_data | def read_data(label, image):
"""
download and read data into numpy
"""
base_url = 'http://yann.lecun.com/exdb/mnist/'
with gzip.open(download_file(base_url+label, os.path.join('data',label))) as flbl:
magic, num = struct.unpack(">II", flbl.read(8))
label = np.fromstring(flbl.read(), ... | python | def read_data(label, image):
"""
download and read data into numpy
"""
base_url = 'http://yann.lecun.com/exdb/mnist/'
with gzip.open(download_file(base_url+label, os.path.join('data',label))) as flbl:
magic, num = struct.unpack(">II", flbl.read(8))
label = np.fromstring(flbl.read(), ... | [
"def",
"read_data",
"(",
"label",
",",
"image",
")",
":",
"base_url",
"=",
"'http://yann.lecun.com/exdb/mnist/'",
"with",
"gzip",
".",
"open",
"(",
"download_file",
"(",
"base_url",
"+",
"label",
",",
"os",
".",
"path",
".",
"join",
"(",
"'data'",
",",
"la... | download and read data into numpy | [
"download",
"and",
"read",
"data",
"into",
"numpy"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/image-classification/train_mnist.py#L31-L42 | train |
apache/incubator-mxnet | example/image-classification/train_mnist.py | get_mnist_iter | def get_mnist_iter(args, kv):
"""
create data iterator with NDArrayIter
"""
(train_lbl, train_img) = read_data(
'train-labels-idx1-ubyte.gz', 'train-images-idx3-ubyte.gz')
(val_lbl, val_img) = read_data(
't10k-labels-idx1-ubyte.gz', 't10k-images-idx3-ubyte.gz')
train = mx... | python | def get_mnist_iter(args, kv):
"""
create data iterator with NDArrayIter
"""
(train_lbl, train_img) = read_data(
'train-labels-idx1-ubyte.gz', 'train-images-idx3-ubyte.gz')
(val_lbl, val_img) = read_data(
't10k-labels-idx1-ubyte.gz', 't10k-images-idx3-ubyte.gz')
train = mx... | [
"def",
"get_mnist_iter",
"(",
"args",
",",
"kv",
")",
":",
"(",
"train_lbl",
",",
"train_img",
")",
"=",
"read_data",
"(",
"'train-labels-idx1-ubyte.gz'",
",",
"'train-images-idx3-ubyte.gz'",
")",
"(",
"val_lbl",
",",
"val_img",
")",
"=",
"read_data",
"(",
"'t... | create data iterator with NDArrayIter | [
"create",
"data",
"iterator",
"with",
"NDArrayIter"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/image-classification/train_mnist.py#L51-L63 | train |
apache/incubator-mxnet | example/fcn-xs/image_segmentaion.py | make_file_extension_assertion | def make_file_extension_assertion(extension):
"""Function factory for file extension argparse assertion
Args:
extension (string): the file extension to assert
Returns:
string: the supplied extension, if assertion is successful.
"""
def file_extension_assertion(file_... | python | def make_file_extension_assertion(extension):
"""Function factory for file extension argparse assertion
Args:
extension (string): the file extension to assert
Returns:
string: the supplied extension, if assertion is successful.
"""
def file_extension_assertion(file_... | [
"def",
"make_file_extension_assertion",
"(",
"extension",
")",
":",
"def",
"file_extension_assertion",
"(",
"file_path",
")",
":",
"base",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"file_path",
")",
"if",
"ext",
".",
"lower",
"(",
")",
"!="... | Function factory for file extension argparse assertion
Args:
extension (string): the file extension to assert
Returns:
string: the supplied extension, if assertion is successful. | [
"Function",
"factory",
"for",
"file",
"extension",
"argparse",
"assertion",
"Args",
":",
"extension",
"(",
"string",
")",
":",
"the",
"file",
"extension",
"to",
"assert"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/fcn-xs/image_segmentaion.py#L31-L45 | train |
apache/incubator-mxnet | example/fcn-xs/image_segmentaion.py | get_palette | def get_palette(num_colors=256):
"""generates the colormap for visualizing the segmentation mask
Args:
num_colors (int): the number of colors to generate in the output palette
Returns:
string: the supplied extension, if assertion is successful.
"""
p... | python | def get_palette(num_colors=256):
"""generates the colormap for visualizing the segmentation mask
Args:
num_colors (int): the number of colors to generate in the output palette
Returns:
string: the supplied extension, if assertion is successful.
"""
p... | [
"def",
"get_palette",
"(",
"num_colors",
"=",
"256",
")",
":",
"pallete",
"=",
"[",
"0",
"]",
"*",
"(",
"num_colors",
"*",
"3",
")",
"for",
"j",
"in",
"range",
"(",
"0",
",",
"num_colors",
")",
":",
"lab",
"=",
"j",
"pallete",
"[",
"j",
"*",
"3... | generates the colormap for visualizing the segmentation mask
Args:
num_colors (int): the number of colors to generate in the output palette
Returns:
string: the supplied extension, if assertion is successful. | [
"generates",
"the",
"colormap",
"for",
"visualizing",
"the",
"segmentation",
"mask",
"Args",
":",
"num_colors",
"(",
"int",
")",
":",
"the",
"number",
"of",
"colors",
"to",
"generate",
"in",
"the",
"output",
"palette"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/fcn-xs/image_segmentaion.py#L47-L69 | train |
apache/incubator-mxnet | example/fcn-xs/image_segmentaion.py | get_data | def get_data(img_path):
"""get the (1, 3, h, w) np.array data for the supplied image
Args:
img_path (string): the input image path
Returns:
np.array: image data in a (1, 3, h, w) shape
"""
mean = np.array([123.68, 116.779, 103.939]) ... | python | def get_data(img_path):
"""get the (1, 3, h, w) np.array data for the supplied image
Args:
img_path (string): the input image path
Returns:
np.array: image data in a (1, 3, h, w) shape
"""
mean = np.array([123.68, 116.779, 103.939]) ... | [
"def",
"get_data",
"(",
"img_path",
")",
":",
"mean",
"=",
"np",
".",
"array",
"(",
"[",
"123.68",
",",
"116.779",
",",
"103.939",
"]",
")",
"# (R,G,B)",
"img",
"=",
"Image",
".",
"open",
"(",
"img_path",
")",
"img",
"=",
"np",
".",
"array",
"(",
... | get the (1, 3, h, w) np.array data for the supplied image
Args:
img_path (string): the input image path
Returns:
np.array: image data in a (1, 3, h, w) shape | [
"get",
"the",
"(",
"1",
"3",
"h",
"w",
")",
"np",
".",
"array",
"data",
"for",
"the",
"supplied",
"image",
"Args",
":",
"img_path",
"(",
"string",
")",
":",
"the",
"input",
"image",
"path"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/fcn-xs/image_segmentaion.py#L71-L88 | train |
apache/incubator-mxnet | example/fcn-xs/image_segmentaion.py | main | def main():
"""Module main execution"""
# Initialization variables - update to change your model and execution context
model_prefix = "FCN8s_VGG16"
epoch = 19
# By default, MXNet will run on the CPU. Change to ctx = mx.gpu() to run on GPU.
ctx = mx.cpu()
fcnxs, fcnxs_args, fcnxs_auxs = mx.... | python | def main():
"""Module main execution"""
# Initialization variables - update to change your model and execution context
model_prefix = "FCN8s_VGG16"
epoch = 19
# By default, MXNet will run on the CPU. Change to ctx = mx.gpu() to run on GPU.
ctx = mx.cpu()
fcnxs, fcnxs_args, fcnxs_auxs = mx.... | [
"def",
"main",
"(",
")",
":",
"# Initialization variables - update to change your model and execution context",
"model_prefix",
"=",
"\"FCN8s_VGG16\"",
"epoch",
"=",
"19",
"# By default, MXNet will run on the CPU. Change to ctx = mx.gpu() to run on GPU.",
"ctx",
"=",
"mx",
".",
"cp... | Module main execution | [
"Module",
"main",
"execution"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/fcn-xs/image_segmentaion.py#L90-L110 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.