repo stringclasses 85
values | path stringlengths 8 121 | func_name stringlengths 1 82 | original_string stringlengths 112 65.5k | language stringclasses 1
value | code stringlengths 112 65.5k | code_tokens listlengths 20 4.09k | docstring stringlengths 3 46.3k | docstring_tokens listlengths 1 564 | sha stringclasses 85
values | url stringlengths 93 218 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
apache/incubator-mxnet | python/mxnet/image/detection.py | ImageDetIter._check_valid_label | def _check_valid_label(self, label):
"""Validate label and its shape."""
if len(label.shape) != 2 or label.shape[1] < 5:
msg = "Label with shape (1+, 5+) required, %s received." % str(label)
raise RuntimeError(msg)
valid_label = np.where(np.logical_and(label[:, 0] >= 0, l... | python | def _check_valid_label(self, label):
"""Validate label and its shape."""
if len(label.shape) != 2 or label.shape[1] < 5:
msg = "Label with shape (1+, 5+) required, %s received." % str(label)
raise RuntimeError(msg)
valid_label = np.where(np.logical_and(label[:, 0] >= 0, l... | [
"def",
"_check_valid_label",
"(",
"self",
",",
"label",
")",
":",
"if",
"len",
"(",
"label",
".",
"shape",
")",
"!=",
"2",
"or",
"label",
".",
"shape",
"[",
"1",
"]",
"<",
"5",
":",
"msg",
"=",
"\"Label with shape (1+, 5+) required, %s received.\"",
"%",
... | Validate label and its shape. | [
"Validate",
"label",
"and",
"its",
"shape",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/detection.py#L692-L700 | train |
apache/incubator-mxnet | python/mxnet/image/detection.py | ImageDetIter._estimate_label_shape | def _estimate_label_shape(self):
"""Helper function to estimate label shape"""
max_count = 0
self.reset()
try:
while True:
label, _ = self.next_sample()
label = self._parse_label(label)
max_count = max(max_count, label.shape[0])... | python | def _estimate_label_shape(self):
"""Helper function to estimate label shape"""
max_count = 0
self.reset()
try:
while True:
label, _ = self.next_sample()
label = self._parse_label(label)
max_count = max(max_count, label.shape[0])... | [
"def",
"_estimate_label_shape",
"(",
"self",
")",
":",
"max_count",
"=",
"0",
"self",
".",
"reset",
"(",
")",
"try",
":",
"while",
"True",
":",
"label",
",",
"_",
"=",
"self",
".",
"next_sample",
"(",
")",
"label",
"=",
"self",
".",
"_parse_label",
"... | Helper function to estimate label shape | [
"Helper",
"function",
"to",
"estimate",
"label",
"shape"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/detection.py#L702-L714 | train |
apache/incubator-mxnet | python/mxnet/image/detection.py | ImageDetIter._parse_label | def _parse_label(self, label):
"""Helper function to parse object detection label.
Format for raw label:
n \t k \t ... \t [id \t xmin\t ymin \t xmax \t ymax \t ...] \t [repeat]
where n is the width of header, 2 or larger
k is the width of each object annotation, can be arbitrary... | python | def _parse_label(self, label):
"""Helper function to parse object detection label.
Format for raw label:
n \t k \t ... \t [id \t xmin\t ymin \t xmax \t ymax \t ...] \t [repeat]
where n is the width of header, 2 or larger
k is the width of each object annotation, can be arbitrary... | [
"def",
"_parse_label",
"(",
"self",
",",
"label",
")",
":",
"if",
"isinstance",
"(",
"label",
",",
"nd",
".",
"NDArray",
")",
":",
"label",
"=",
"label",
".",
"asnumpy",
"(",
")",
"raw",
"=",
"label",
".",
"ravel",
"(",
")",
"if",
"raw",
".",
"si... | Helper function to parse object detection label.
Format for raw label:
n \t k \t ... \t [id \t xmin\t ymin \t xmax \t ymax \t ...] \t [repeat]
where n is the width of header, 2 or larger
k is the width of each object annotation, can be arbitrary, at least 5 | [
"Helper",
"function",
"to",
"parse",
"object",
"detection",
"label",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/detection.py#L716-L740 | train |
apache/incubator-mxnet | python/mxnet/image/detection.py | ImageDetIter.reshape | def reshape(self, data_shape=None, label_shape=None):
"""Reshape iterator for data_shape or label_shape.
Parameters
----------
data_shape : tuple or None
Reshape the data_shape to the new shape if not None
label_shape : tuple or None
Reshape label shape t... | python | def reshape(self, data_shape=None, label_shape=None):
"""Reshape iterator for data_shape or label_shape.
Parameters
----------
data_shape : tuple or None
Reshape the data_shape to the new shape if not None
label_shape : tuple or None
Reshape label shape t... | [
"def",
"reshape",
"(",
"self",
",",
"data_shape",
"=",
"None",
",",
"label_shape",
"=",
"None",
")",
":",
"if",
"data_shape",
"is",
"not",
"None",
":",
"self",
".",
"check_data_shape",
"(",
"data_shape",
")",
"self",
".",
"provide_data",
"=",
"[",
"(",
... | Reshape iterator for data_shape or label_shape.
Parameters
----------
data_shape : tuple or None
Reshape the data_shape to the new shape if not None
label_shape : tuple or None
Reshape label shape to new shape if not None | [
"Reshape",
"iterator",
"for",
"data_shape",
"or",
"label_shape",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/detection.py#L742-L759 | train |
apache/incubator-mxnet | python/mxnet/image/detection.py | ImageDetIter._batchify | def _batchify(self, batch_data, batch_label, start=0):
"""Override the helper function for batchifying data"""
i = start
batch_size = self.batch_size
try:
while i < batch_size:
label, s = self.next_sample()
data = self.imdecode(s)
... | python | def _batchify(self, batch_data, batch_label, start=0):
"""Override the helper function for batchifying data"""
i = start
batch_size = self.batch_size
try:
while i < batch_size:
label, s = self.next_sample()
data = self.imdecode(s)
... | [
"def",
"_batchify",
"(",
"self",
",",
"batch_data",
",",
"batch_label",
",",
"start",
"=",
"0",
")",
":",
"i",
"=",
"start",
"batch_size",
"=",
"self",
".",
"batch_size",
"try",
":",
"while",
"i",
"<",
"batch_size",
":",
"label",
",",
"s",
"=",
"self... | Override the helper function for batchifying data | [
"Override",
"the",
"helper",
"function",
"for",
"batchifying",
"data"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/detection.py#L761-L789 | train |
apache/incubator-mxnet | python/mxnet/image/detection.py | ImageDetIter.next | def next(self):
"""Override the function for returning next batch."""
batch_size = self.batch_size
c, h, w = self.data_shape
# if last batch data is rolled over
if self._cache_data is not None:
# check both the data and label have values
assert self._cache... | python | def next(self):
"""Override the function for returning next batch."""
batch_size = self.batch_size
c, h, w = self.data_shape
# if last batch data is rolled over
if self._cache_data is not None:
# check both the data and label have values
assert self._cache... | [
"def",
"next",
"(",
"self",
")",
":",
"batch_size",
"=",
"self",
".",
"batch_size",
"c",
",",
"h",
",",
"w",
"=",
"self",
".",
"data_shape",
"# if last batch data is rolled over",
"if",
"self",
".",
"_cache_data",
"is",
"not",
"None",
":",
"# check both the ... | Override the function for returning next batch. | [
"Override",
"the",
"function",
"for",
"returning",
"next",
"batch",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/detection.py#L791-L830 | train |
apache/incubator-mxnet | python/mxnet/image/detection.py | ImageDetIter.augmentation_transform | def augmentation_transform(self, data, label): # pylint: disable=arguments-differ
"""Override Transforms input data with specified augmentations."""
for aug in self.auglist:
data, label = aug(data, label)
return (data, label) | python | def augmentation_transform(self, data, label): # pylint: disable=arguments-differ
"""Override Transforms input data with specified augmentations."""
for aug in self.auglist:
data, label = aug(data, label)
return (data, label) | [
"def",
"augmentation_transform",
"(",
"self",
",",
"data",
",",
"label",
")",
":",
"# pylint: disable=arguments-differ",
"for",
"aug",
"in",
"self",
".",
"auglist",
":",
"data",
",",
"label",
"=",
"aug",
"(",
"data",
",",
"label",
")",
"return",
"(",
"data... | Override Transforms input data with specified augmentations. | [
"Override",
"Transforms",
"input",
"data",
"with",
"specified",
"augmentations",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/detection.py#L832-L836 | train |
apache/incubator-mxnet | python/mxnet/image/detection.py | ImageDetIter.check_label_shape | def check_label_shape(self, label_shape):
"""Checks if the new label shape is valid"""
if not len(label_shape) == 2:
raise ValueError('label_shape should have length 2')
if label_shape[0] < self.label_shape[0]:
msg = 'Attempts to reduce label count from %d to %d, not allo... | python | def check_label_shape(self, label_shape):
"""Checks if the new label shape is valid"""
if not len(label_shape) == 2:
raise ValueError('label_shape should have length 2')
if label_shape[0] < self.label_shape[0]:
msg = 'Attempts to reduce label count from %d to %d, not allo... | [
"def",
"check_label_shape",
"(",
"self",
",",
"label_shape",
")",
":",
"if",
"not",
"len",
"(",
"label_shape",
")",
"==",
"2",
":",
"raise",
"ValueError",
"(",
"'label_shape should have length 2'",
")",
"if",
"label_shape",
"[",
"0",
"]",
"<",
"self",
".",
... | Checks if the new label shape is valid | [
"Checks",
"if",
"the",
"new",
"label",
"shape",
"is",
"valid"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/detection.py#L838-L849 | train |
apache/incubator-mxnet | python/mxnet/image/detection.py | ImageDetIter.draw_next | def draw_next(self, color=None, thickness=2, mean=None, std=None, clip=True,
waitKey=None, window_name='draw_next', id2labels=None):
"""Display next image with bounding boxes drawn.
Parameters
----------
color : tuple
Bounding box color in RGB, use None for... | python | def draw_next(self, color=None, thickness=2, mean=None, std=None, clip=True,
waitKey=None, window_name='draw_next', id2labels=None):
"""Display next image with bounding boxes drawn.
Parameters
----------
color : tuple
Bounding box color in RGB, use None for... | [
"def",
"draw_next",
"(",
"self",
",",
"color",
"=",
"None",
",",
"thickness",
"=",
"2",
",",
"mean",
"=",
"None",
",",
"std",
"=",
"None",
",",
"clip",
"=",
"True",
",",
"waitKey",
"=",
"None",
",",
"window_name",
"=",
"'draw_next'",
",",
"id2labels"... | Display next image with bounding boxes drawn.
Parameters
----------
color : tuple
Bounding box color in RGB, use None for random color
thickness : int
Bounding box border thickness
mean : True or numpy.ndarray
Compensate for the mean to have b... | [
"Display",
"next",
"image",
"with",
"bounding",
"boxes",
"drawn",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/detection.py#L851-L957 | train |
apache/incubator-mxnet | python/mxnet/image/detection.py | ImageDetIter.sync_label_shape | def sync_label_shape(self, it, verbose=False):
"""Synchronize label shape with the input iterator. This is useful when
train/validation iterators have different label padding.
Parameters
----------
it : ImageDetIter
The other iterator to synchronize
verbose :... | python | def sync_label_shape(self, it, verbose=False):
"""Synchronize label shape with the input iterator. This is useful when
train/validation iterators have different label padding.
Parameters
----------
it : ImageDetIter
The other iterator to synchronize
verbose :... | [
"def",
"sync_label_shape",
"(",
"self",
",",
"it",
",",
"verbose",
"=",
"False",
")",
":",
"assert",
"isinstance",
"(",
"it",
",",
"ImageDetIter",
")",
",",
"'Synchronize with invalid iterator.'",
"train_label_shape",
"=",
"self",
".",
"label_shape",
"val_label_sh... | Synchronize label shape with the input iterator. This is useful when
train/validation iterators have different label padding.
Parameters
----------
it : ImageDetIter
The other iterator to synchronize
verbose : bool
Print verbose log if true
Retur... | [
"Synchronize",
"label",
"shape",
"with",
"the",
"input",
"iterator",
".",
"This",
"is",
"useful",
"when",
"train",
"/",
"validation",
"iterators",
"have",
"different",
"label",
"padding",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/image/detection.py#L959-L1000 | train |
apache/incubator-mxnet | example/rcnn/symdata/anchor.py | AnchorGenerator._generate_base_anchors | def _generate_base_anchors(base_size, scales, ratios):
"""
Generate anchor (reference) windows by enumerating aspect ratios X
scales wrt a reference (0, 0, 15, 15) window.
"""
base_anchor = np.array([1, 1, base_size, base_size]) - 1
ratio_anchors = AnchorGenerator._ratio_... | python | def _generate_base_anchors(base_size, scales, ratios):
"""
Generate anchor (reference) windows by enumerating aspect ratios X
scales wrt a reference (0, 0, 15, 15) window.
"""
base_anchor = np.array([1, 1, base_size, base_size]) - 1
ratio_anchors = AnchorGenerator._ratio_... | [
"def",
"_generate_base_anchors",
"(",
"base_size",
",",
"scales",
",",
"ratios",
")",
":",
"base_anchor",
"=",
"np",
".",
"array",
"(",
"[",
"1",
",",
"1",
",",
"base_size",
",",
"base_size",
"]",
")",
"-",
"1",
"ratio_anchors",
"=",
"AnchorGenerator",
"... | Generate anchor (reference) windows by enumerating aspect ratios X
scales wrt a reference (0, 0, 15, 15) window. | [
"Generate",
"anchor",
"(",
"reference",
")",
"windows",
"by",
"enumerating",
"aspect",
"ratios",
"X",
"scales",
"wrt",
"a",
"reference",
"(",
"0",
"0",
"15",
"15",
")",
"window",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/rcnn/symdata/anchor.py#L44-L53 | train |
apache/incubator-mxnet | example/rcnn/symdata/anchor.py | AnchorGenerator._whctrs | def _whctrs(anchor):
"""
Return width, height, x center, and y center for an anchor (window).
"""
w = anchor[2] - anchor[0] + 1
h = anchor[3] - anchor[1] + 1
x_ctr = anchor[0] + 0.5 * (w - 1)
y_ctr = anchor[1] + 0.5 * (h - 1)
return w, h, x_ctr, y_ctr | python | def _whctrs(anchor):
"""
Return width, height, x center, and y center for an anchor (window).
"""
w = anchor[2] - anchor[0] + 1
h = anchor[3] - anchor[1] + 1
x_ctr = anchor[0] + 0.5 * (w - 1)
y_ctr = anchor[1] + 0.5 * (h - 1)
return w, h, x_ctr, y_ctr | [
"def",
"_whctrs",
"(",
"anchor",
")",
":",
"w",
"=",
"anchor",
"[",
"2",
"]",
"-",
"anchor",
"[",
"0",
"]",
"+",
"1",
"h",
"=",
"anchor",
"[",
"3",
"]",
"-",
"anchor",
"[",
"1",
"]",
"+",
"1",
"x_ctr",
"=",
"anchor",
"[",
"0",
"]",
"+",
"... | Return width, height, x center, and y center for an anchor (window). | [
"Return",
"width",
"height",
"x",
"center",
"and",
"y",
"center",
"for",
"an",
"anchor",
"(",
"window",
")",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/rcnn/symdata/anchor.py#L56-L64 | train |
apache/incubator-mxnet | example/rcnn/symdata/anchor.py | AnchorGenerator._mkanchors | def _mkanchors(ws, hs, x_ctr, y_ctr):
"""
Given a vector of widths (ws) and heights (hs) around a center
(x_ctr, y_ctr), output a set of anchors (windows).
"""
ws = ws[:, np.newaxis]
hs = hs[:, np.newaxis]
anchors = np.hstack((x_ctr - 0.5 * (ws - 1),
... | python | def _mkanchors(ws, hs, x_ctr, y_ctr):
"""
Given a vector of widths (ws) and heights (hs) around a center
(x_ctr, y_ctr), output a set of anchors (windows).
"""
ws = ws[:, np.newaxis]
hs = hs[:, np.newaxis]
anchors = np.hstack((x_ctr - 0.5 * (ws - 1),
... | [
"def",
"_mkanchors",
"(",
"ws",
",",
"hs",
",",
"x_ctr",
",",
"y_ctr",
")",
":",
"ws",
"=",
"ws",
"[",
":",
",",
"np",
".",
"newaxis",
"]",
"hs",
"=",
"hs",
"[",
":",
",",
"np",
".",
"newaxis",
"]",
"anchors",
"=",
"np",
".",
"hstack",
"(",
... | Given a vector of widths (ws) and heights (hs) around a center
(x_ctr, y_ctr), output a set of anchors (windows). | [
"Given",
"a",
"vector",
"of",
"widths",
"(",
"ws",
")",
"and",
"heights",
"(",
"hs",
")",
"around",
"a",
"center",
"(",
"x_ctr",
"y_ctr",
")",
"output",
"a",
"set",
"of",
"anchors",
"(",
"windows",
")",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/rcnn/symdata/anchor.py#L67-L78 | train |
apache/incubator-mxnet | example/rcnn/symdata/anchor.py | AnchorGenerator._ratio_enum | def _ratio_enum(anchor, ratios):
"""
Enumerate a set of anchors for each aspect ratio wrt an anchor.
"""
w, h, x_ctr, y_ctr = AnchorGenerator._whctrs(anchor)
size = w * h
size_ratios = size / ratios
ws = np.round(np.sqrt(size_ratios))
hs = np.round(ws * ra... | python | def _ratio_enum(anchor, ratios):
"""
Enumerate a set of anchors for each aspect ratio wrt an anchor.
"""
w, h, x_ctr, y_ctr = AnchorGenerator._whctrs(anchor)
size = w * h
size_ratios = size / ratios
ws = np.round(np.sqrt(size_ratios))
hs = np.round(ws * ra... | [
"def",
"_ratio_enum",
"(",
"anchor",
",",
"ratios",
")",
":",
"w",
",",
"h",
",",
"x_ctr",
",",
"y_ctr",
"=",
"AnchorGenerator",
".",
"_whctrs",
"(",
"anchor",
")",
"size",
"=",
"w",
"*",
"h",
"size_ratios",
"=",
"size",
"/",
"ratios",
"ws",
"=",
"... | Enumerate a set of anchors for each aspect ratio wrt an anchor. | [
"Enumerate",
"a",
"set",
"of",
"anchors",
"for",
"each",
"aspect",
"ratio",
"wrt",
"an",
"anchor",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/rcnn/symdata/anchor.py#L81-L91 | train |
apache/incubator-mxnet | example/rcnn/symdata/anchor.py | AnchorGenerator._scale_enum | def _scale_enum(anchor, scales):
"""
Enumerate a set of anchors for each scale wrt an anchor.
"""
w, h, x_ctr, y_ctr = AnchorGenerator._whctrs(anchor)
ws = w * scales
hs = h * scales
anchors = AnchorGenerator._mkanchors(ws, hs, x_ctr, y_ctr)
return anchors | python | def _scale_enum(anchor, scales):
"""
Enumerate a set of anchors for each scale wrt an anchor.
"""
w, h, x_ctr, y_ctr = AnchorGenerator._whctrs(anchor)
ws = w * scales
hs = h * scales
anchors = AnchorGenerator._mkanchors(ws, hs, x_ctr, y_ctr)
return anchors | [
"def",
"_scale_enum",
"(",
"anchor",
",",
"scales",
")",
":",
"w",
",",
"h",
",",
"x_ctr",
",",
"y_ctr",
"=",
"AnchorGenerator",
".",
"_whctrs",
"(",
"anchor",
")",
"ws",
"=",
"w",
"*",
"scales",
"hs",
"=",
"h",
"*",
"scales",
"anchors",
"=",
"Anch... | Enumerate a set of anchors for each scale wrt an anchor. | [
"Enumerate",
"a",
"set",
"of",
"anchors",
"for",
"each",
"scale",
"wrt",
"an",
"anchor",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/rcnn/symdata/anchor.py#L94-L102 | train |
apache/incubator-mxnet | example/speech_recognition/arch_deepspeech.py | prepare_data | def prepare_data(args):
"""
set atual shape of data
"""
rnn_type = args.config.get("arch", "rnn_type")
num_rnn_layer = args.config.getint("arch", "num_rnn_layer")
num_hidden_rnn_list = json.loads(args.config.get("arch", "num_hidden_rnn_list"))
batch_size = args.config.getint("common", "batc... | python | def prepare_data(args):
"""
set atual shape of data
"""
rnn_type = args.config.get("arch", "rnn_type")
num_rnn_layer = args.config.getint("arch", "num_rnn_layer")
num_hidden_rnn_list = json.loads(args.config.get("arch", "num_hidden_rnn_list"))
batch_size = args.config.getint("common", "batc... | [
"def",
"prepare_data",
"(",
"args",
")",
":",
"rnn_type",
"=",
"args",
".",
"config",
".",
"get",
"(",
"\"arch\"",
",",
"\"rnn_type\"",
")",
"num_rnn_layer",
"=",
"args",
".",
"config",
".",
"getint",
"(",
"\"arch\"",
",",
"\"num_rnn_layer\"",
")",
"num_hi... | set atual shape of data | [
"set",
"atual",
"shape",
"of",
"data"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/speech_recognition/arch_deepspeech.py#L38-L80 | train |
apache/incubator-mxnet | example/speech_recognition/arch_deepspeech.py | arch | def arch(args, seq_len=None):
"""
define deep speech 2 network
"""
if isinstance(args, argparse.Namespace):
mode = args.config.get("common", "mode")
is_bucketing = args.config.getboolean("arch", "is_bucketing")
if mode == "train" or is_bucketing:
channel_num = args.co... | python | def arch(args, seq_len=None):
"""
define deep speech 2 network
"""
if isinstance(args, argparse.Namespace):
mode = args.config.get("common", "mode")
is_bucketing = args.config.getboolean("arch", "is_bucketing")
if mode == "train" or is_bucketing:
channel_num = args.co... | [
"def",
"arch",
"(",
"args",
",",
"seq_len",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"args",
",",
"argparse",
".",
"Namespace",
")",
":",
"mode",
"=",
"args",
".",
"config",
".",
"get",
"(",
"\"common\"",
",",
"\"mode\"",
")",
"is_bucketing",
... | define deep speech 2 network | [
"define",
"deep",
"speech",
"2",
"network"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/speech_recognition/arch_deepspeech.py#L83-L206 | train |
apache/incubator-mxnet | example/gluon/lipnet/main.py | main | def main():
"""
Description : run lipnet training code using argument info
"""
parser = argparse.ArgumentParser()
parser.add_argument('--batch_size', type=int, default=64)
parser.add_argument('--epochs', type=int, default=100)
parser.add_argument('--image_path', type=str, default='./data/dat... | python | def main():
"""
Description : run lipnet training code using argument info
"""
parser = argparse.ArgumentParser()
parser.add_argument('--batch_size', type=int, default=64)
parser.add_argument('--epochs', type=int, default=100)
parser.add_argument('--image_path', type=str, default='./data/dat... | [
"def",
"main",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"'--batch_size'",
",",
"type",
"=",
"int",
",",
"default",
"=",
"64",
")",
"parser",
".",
"add_argument",
"(",
"'--epochs'",
","... | Description : run lipnet training code using argument info | [
"Description",
":",
"run",
"lipnet",
"training",
"code",
"using",
"argument",
"info"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/lipnet/main.py#L26-L43 | train |
apache/incubator-mxnet | example/rcnn/symdata/vis.py | vis_detection | def vis_detection(im_orig, detections, class_names, thresh=0.7):
"""visualize [cls, conf, x1, y1, x2, y2]"""
import matplotlib.pyplot as plt
import random
plt.imshow(im_orig)
colors = [(random.random(), random.random(), random.random()) for _ in class_names]
for [cls, conf, x1, y1, x2, y2] in de... | python | def vis_detection(im_orig, detections, class_names, thresh=0.7):
"""visualize [cls, conf, x1, y1, x2, y2]"""
import matplotlib.pyplot as plt
import random
plt.imshow(im_orig)
colors = [(random.random(), random.random(), random.random()) for _ in class_names]
for [cls, conf, x1, y1, x2, y2] in de... | [
"def",
"vis_detection",
"(",
"im_orig",
",",
"detections",
",",
"class_names",
",",
"thresh",
"=",
"0.7",
")",
":",
"import",
"matplotlib",
".",
"pyplot",
"as",
"plt",
"import",
"random",
"plt",
".",
"imshow",
"(",
"im_orig",
")",
"colors",
"=",
"[",
"("... | visualize [cls, conf, x1, y1, x2, y2] | [
"visualize",
"[",
"cls",
"conf",
"x1",
"y1",
"x2",
"y2",
"]"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/rcnn/symdata/vis.py#L18-L32 | train |
apache/incubator-mxnet | tools/coreml/converter/_mxnet_converter.py | check_error | def check_error(model, path, shapes, output = 'softmax_output', verbose = True):
"""
Check the difference between predictions from MXNet and CoreML.
"""
coreml_model = _coremltools.models.MLModel(path)
input_data = {}
input_data_copy = {}
for ip in shapes:
input_data[ip] = _np.random... | python | def check_error(model, path, shapes, output = 'softmax_output', verbose = True):
"""
Check the difference between predictions from MXNet and CoreML.
"""
coreml_model = _coremltools.models.MLModel(path)
input_data = {}
input_data_copy = {}
for ip in shapes:
input_data[ip] = _np.random... | [
"def",
"check_error",
"(",
"model",
",",
"path",
",",
"shapes",
",",
"output",
"=",
"'softmax_output'",
",",
"verbose",
"=",
"True",
")",
":",
"coreml_model",
"=",
"_coremltools",
".",
"models",
".",
"MLModel",
"(",
"path",
")",
"input_data",
"=",
"{",
"... | Check the difference between predictions from MXNet and CoreML. | [
"Check",
"the",
"difference",
"between",
"predictions",
"from",
"MXNet",
"and",
"CoreML",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/tools/coreml/converter/_mxnet_converter.py#L56-L78 | train |
apache/incubator-mxnet | example/gluon/lipnet/trainer.py | setting_ctx | def setting_ctx(num_gpus):
"""
Description : set gpu module
"""
if num_gpus > 0:
ctx = [mx.gpu(i) for i in range(num_gpus)]
else:
ctx = [mx.cpu()]
return ctx | python | def setting_ctx(num_gpus):
"""
Description : set gpu module
"""
if num_gpus > 0:
ctx = [mx.gpu(i) for i in range(num_gpus)]
else:
ctx = [mx.cpu()]
return ctx | [
"def",
"setting_ctx",
"(",
"num_gpus",
")",
":",
"if",
"num_gpus",
">",
"0",
":",
"ctx",
"=",
"[",
"mx",
".",
"gpu",
"(",
"i",
")",
"for",
"i",
"in",
"range",
"(",
"num_gpus",
")",
"]",
"else",
":",
"ctx",
"=",
"[",
"mx",
".",
"cpu",
"(",
")"... | Description : set gpu module | [
"Description",
":",
"set",
"gpu",
"module"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/lipnet/trainer.py#L35-L43 | train |
apache/incubator-mxnet | example/gluon/lipnet/trainer.py | char_beam_search | def char_beam_search(out):
"""
Description : apply beam search for prediction result
"""
out_conv = list()
for idx in range(out.shape[0]):
probs = out[idx]
prob = probs.softmax().asnumpy()
line_string_proposals = ctcBeamSearch(prob, ALPHABET, None, k=4, beamWidth=25)
... | python | def char_beam_search(out):
"""
Description : apply beam search for prediction result
"""
out_conv = list()
for idx in range(out.shape[0]):
probs = out[idx]
prob = probs.softmax().asnumpy()
line_string_proposals = ctcBeamSearch(prob, ALPHABET, None, k=4, beamWidth=25)
... | [
"def",
"char_beam_search",
"(",
"out",
")",
":",
"out_conv",
"=",
"list",
"(",
")",
"for",
"idx",
"in",
"range",
"(",
"out",
".",
"shape",
"[",
"0",
"]",
")",
":",
"probs",
"=",
"out",
"[",
"idx",
"]",
"prob",
"=",
"probs",
".",
"softmax",
"(",
... | Description : apply beam search for prediction result | [
"Description",
":",
"apply",
"beam",
"search",
"for",
"prediction",
"result"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/lipnet/trainer.py#L50-L60 | train |
apache/incubator-mxnet | example/gluon/lipnet/trainer.py | Train.build_model | def build_model(self, dr_rate=0, path=None):
"""
Description : build network
"""
#set network
self.net = LipNet(dr_rate)
self.net.hybridize()
self.net.initialize(ctx=self.ctx)
if path is not None:
self.load_model(path)
#set optimizer
... | python | def build_model(self, dr_rate=0, path=None):
"""
Description : build network
"""
#set network
self.net = LipNet(dr_rate)
self.net.hybridize()
self.net.initialize(ctx=self.ctx)
if path is not None:
self.load_model(path)
#set optimizer
... | [
"def",
"build_model",
"(",
"self",
",",
"dr_rate",
"=",
"0",
",",
"path",
"=",
"None",
")",
":",
"#set network",
"self",
".",
"net",
"=",
"LipNet",
"(",
"dr_rate",
")",
"self",
".",
"net",
".",
"hybridize",
"(",
")",
"self",
".",
"net",
".",
"initi... | Description : build network | [
"Description",
":",
"build",
"network"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/lipnet/trainer.py#L77-L92 | train |
apache/incubator-mxnet | example/gluon/lipnet/trainer.py | Train.save_model | def save_model(self, epoch, loss):
"""
Description : save parameter of network weight
"""
prefix = 'checkpoint/epoches'
file_name = "{prefix}_{epoch}_loss_{l:.4f}".format(prefix=prefix,
epoch=str(epoch),
... | python | def save_model(self, epoch, loss):
"""
Description : save parameter of network weight
"""
prefix = 'checkpoint/epoches'
file_name = "{prefix}_{epoch}_loss_{l:.4f}".format(prefix=prefix,
epoch=str(epoch),
... | [
"def",
"save_model",
"(",
"self",
",",
"epoch",
",",
"loss",
")",
":",
"prefix",
"=",
"'checkpoint/epoches'",
"file_name",
"=",
"\"{prefix}_{epoch}_loss_{l:.4f}\"",
".",
"format",
"(",
"prefix",
"=",
"prefix",
",",
"epoch",
"=",
"str",
"(",
"epoch",
")",
","... | Description : save parameter of network weight | [
"Description",
":",
"save",
"parameter",
"of",
"network",
"weight"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/lipnet/trainer.py#L94-L102 | train |
apache/incubator-mxnet | example/gluon/lipnet/trainer.py | Train.load_dataloader | def load_dataloader(self):
"""
Description : Setup the dataloader
"""
input_transform = transforms.Compose([transforms.ToTensor(), \
transforms.Normalize((0.7136, 0.4906, 0.3283), \
... | python | def load_dataloader(self):
"""
Description : Setup the dataloader
"""
input_transform = transforms.Compose([transforms.ToTensor(), \
transforms.Normalize((0.7136, 0.4906, 0.3283), \
... | [
"def",
"load_dataloader",
"(",
"self",
")",
":",
"input_transform",
"=",
"transforms",
".",
"Compose",
"(",
"[",
"transforms",
".",
"ToTensor",
"(",
")",
",",
"transforms",
".",
"Normalize",
"(",
"(",
"0.7136",
",",
"0.4906",
",",
"0.3283",
")",
",",
"("... | Description : Setup the dataloader | [
"Description",
":",
"Setup",
"the",
"dataloader"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/lipnet/trainer.py#L110-L138 | train |
apache/incubator-mxnet | example/gluon/lipnet/trainer.py | Train.train | def train(self, data, label, batch_size):
"""
Description : training for LipNet
"""
# pylint: disable=no-member
sum_losses = 0
len_losses = 0
with autograd.record():
losses = [self.loss_fn(self.net(X), Y) for X, Y in zip(data, label)]
for loss ... | python | def train(self, data, label, batch_size):
"""
Description : training for LipNet
"""
# pylint: disable=no-member
sum_losses = 0
len_losses = 0
with autograd.record():
losses = [self.loss_fn(self.net(X), Y) for X, Y in zip(data, label)]
for loss ... | [
"def",
"train",
"(",
"self",
",",
"data",
",",
"label",
",",
"batch_size",
")",
":",
"# pylint: disable=no-member",
"sum_losses",
"=",
"0",
"len_losses",
"=",
"0",
"with",
"autograd",
".",
"record",
"(",
")",
":",
"losses",
"=",
"[",
"self",
".",
"loss_f... | Description : training for LipNet | [
"Description",
":",
"training",
"for",
"LipNet"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/lipnet/trainer.py#L140-L154 | train |
apache/incubator-mxnet | example/gluon/lipnet/trainer.py | Train.infer | def infer(self, input_data, input_label):
"""
Description : Print sentence for prediction result
"""
sum_losses = 0
len_losses = 0
for data, label in zip(input_data, input_label):
pred = self.net(data)
sum_losses += mx.nd.array(self.loss_fn(pred, l... | python | def infer(self, input_data, input_label):
"""
Description : Print sentence for prediction result
"""
sum_losses = 0
len_losses = 0
for data, label in zip(input_data, input_label):
pred = self.net(data)
sum_losses += mx.nd.array(self.loss_fn(pred, l... | [
"def",
"infer",
"(",
"self",
",",
"input_data",
",",
"input_label",
")",
":",
"sum_losses",
"=",
"0",
"len_losses",
"=",
"0",
"for",
"data",
",",
"label",
"in",
"zip",
"(",
"input_data",
",",
"input_label",
")",
":",
"pred",
"=",
"self",
".",
"net",
... | Description : Print sentence for prediction result | [
"Description",
":",
"Print",
"sentence",
"for",
"prediction",
"result"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/lipnet/trainer.py#L156-L170 | train |
apache/incubator-mxnet | example/gluon/lipnet/trainer.py | Train.train_batch | def train_batch(self, dataloader):
"""
Description : training for LipNet
"""
sum_losses = 0
len_losses = 0
for input_data, input_label in tqdm(dataloader):
data = gluon.utils.split_and_load(input_data, self.ctx, even_split=False)
label = gluon.util... | python | def train_batch(self, dataloader):
"""
Description : training for LipNet
"""
sum_losses = 0
len_losses = 0
for input_data, input_label in tqdm(dataloader):
data = gluon.utils.split_and_load(input_data, self.ctx, even_split=False)
label = gluon.util... | [
"def",
"train_batch",
"(",
"self",
",",
"dataloader",
")",
":",
"sum_losses",
"=",
"0",
"len_losses",
"=",
"0",
"for",
"input_data",
",",
"input_label",
"in",
"tqdm",
"(",
"dataloader",
")",
":",
"data",
"=",
"gluon",
".",
"utils",
".",
"split_and_load",
... | Description : training for LipNet | [
"Description",
":",
"training",
"for",
"LipNet"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/lipnet/trainer.py#L172-L186 | train |
apache/incubator-mxnet | example/gluon/lipnet/trainer.py | Train.infer_batch | def infer_batch(self, dataloader):
"""
Description : inference for LipNet
"""
sum_losses = 0
len_losses = 0
for input_data, input_label in dataloader:
data = gluon.utils.split_and_load(input_data, self.ctx, even_split=False)
label = gluon.utils.spl... | python | def infer_batch(self, dataloader):
"""
Description : inference for LipNet
"""
sum_losses = 0
len_losses = 0
for input_data, input_label in dataloader:
data = gluon.utils.split_and_load(input_data, self.ctx, even_split=False)
label = gluon.utils.spl... | [
"def",
"infer_batch",
"(",
"self",
",",
"dataloader",
")",
":",
"sum_losses",
"=",
"0",
"len_losses",
"=",
"0",
"for",
"input_data",
",",
"input_label",
"in",
"dataloader",
":",
"data",
"=",
"gluon",
".",
"utils",
".",
"split_and_load",
"(",
"input_data",
... | Description : inference for LipNet | [
"Description",
":",
"inference",
"for",
"LipNet"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/lipnet/trainer.py#L188-L201 | train |
apache/incubator-mxnet | example/gluon/lipnet/trainer.py | Train.run | def run(self, epochs):
"""
Description : Run training for LipNet
"""
best_loss = sys.maxsize
for epoch in trange(epochs):
iter_no = 0
## train
sum_losses, len_losses = self.train_batch(self.train_dataloader)
if iter_no % 20 == 0:
... | python | def run(self, epochs):
"""
Description : Run training for LipNet
"""
best_loss = sys.maxsize
for epoch in trange(epochs):
iter_no = 0
## train
sum_losses, len_losses = self.train_batch(self.train_dataloader)
if iter_no % 20 == 0:
... | [
"def",
"run",
"(",
"self",
",",
"epochs",
")",
":",
"best_loss",
"=",
"sys",
".",
"maxsize",
"for",
"epoch",
"in",
"trange",
"(",
"epochs",
")",
":",
"iter_no",
"=",
"0",
"## train",
"sum_losses",
",",
"len_losses",
"=",
"self",
".",
"train_batch",
"("... | Description : Run training for LipNet | [
"Description",
":",
"Run",
"training",
"for",
"LipNet"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/lipnet/trainer.py#L203-L232 | train |
apache/incubator-mxnet | example/reinforcement-learning/dqn/utils.py | sample_categorical | def sample_categorical(prob, rng):
"""Sample from independent categorical distributions
Each batch is an independent categorical distribution.
Parameters
----------
prob : numpy.ndarray
Probability of the categorical distribution. Shape --> (batch_num, category_num)
rng : numpy.random.Ra... | python | def sample_categorical(prob, rng):
"""Sample from independent categorical distributions
Each batch is an independent categorical distribution.
Parameters
----------
prob : numpy.ndarray
Probability of the categorical distribution. Shape --> (batch_num, category_num)
rng : numpy.random.Ra... | [
"def",
"sample_categorical",
"(",
"prob",
",",
"rng",
")",
":",
"ret",
"=",
"numpy",
".",
"empty",
"(",
"prob",
".",
"shape",
"[",
"0",
"]",
",",
"dtype",
"=",
"numpy",
".",
"float32",
")",
"for",
"ind",
"in",
"range",
"(",
"prob",
".",
"shape",
... | Sample from independent categorical distributions
Each batch is an independent categorical distribution.
Parameters
----------
prob : numpy.ndarray
Probability of the categorical distribution. Shape --> (batch_num, category_num)
rng : numpy.random.RandomState
Returns
-------
ret... | [
"Sample",
"from",
"independent",
"categorical",
"distributions"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/reinforcement-learning/dqn/utils.py#L133-L154 | train |
apache/incubator-mxnet | example/reinforcement-learning/dqn/utils.py | sample_normal | def sample_normal(mean, var, rng):
"""Sample from independent normal distributions
Each element is an independent normal distribution.
Parameters
----------
mean : numpy.ndarray
Means of the normal distribution. Shape --> (batch_num, sample_dim)
var : numpy.ndarray
Variance of the ... | python | def sample_normal(mean, var, rng):
"""Sample from independent normal distributions
Each element is an independent normal distribution.
Parameters
----------
mean : numpy.ndarray
Means of the normal distribution. Shape --> (batch_num, sample_dim)
var : numpy.ndarray
Variance of the ... | [
"def",
"sample_normal",
"(",
"mean",
",",
"var",
",",
"rng",
")",
":",
"ret",
"=",
"numpy",
".",
"sqrt",
"(",
"var",
")",
"*",
"rng",
".",
"randn",
"(",
"*",
"mean",
".",
"shape",
")",
"+",
"mean",
"return",
"ret"
] | Sample from independent normal distributions
Each element is an independent normal distribution.
Parameters
----------
mean : numpy.ndarray
Means of the normal distribution. Shape --> (batch_num, sample_dim)
var : numpy.ndarray
Variance of the normal distribution. Shape --> (batch_num,... | [
"Sample",
"from",
"independent",
"normal",
"distributions"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/reinforcement-learning/dqn/utils.py#L157-L176 | train |
apache/incubator-mxnet | example/reinforcement-learning/dqn/utils.py | sample_mog | def sample_mog(prob, mean, var, rng):
"""Sample from independent mixture of gaussian (MoG) distributions
Each batch is an independent MoG distribution.
Parameters
----------
prob : numpy.ndarray
mixture probability of each gaussian. Shape --> (batch_num, center_num)
mean : numpy.ndarray
... | python | def sample_mog(prob, mean, var, rng):
"""Sample from independent mixture of gaussian (MoG) distributions
Each batch is an independent MoG distribution.
Parameters
----------
prob : numpy.ndarray
mixture probability of each gaussian. Shape --> (batch_num, center_num)
mean : numpy.ndarray
... | [
"def",
"sample_mog",
"(",
"prob",
",",
"mean",
",",
"var",
",",
"rng",
")",
":",
"gaussian_inds",
"=",
"sample_categorical",
"(",
"prob",
",",
"rng",
")",
".",
"astype",
"(",
"numpy",
".",
"int32",
")",
"mean",
"=",
"mean",
"[",
"numpy",
".",
"arange... | Sample from independent mixture of gaussian (MoG) distributions
Each batch is an independent MoG distribution.
Parameters
----------
prob : numpy.ndarray
mixture probability of each gaussian. Shape --> (batch_num, center_num)
mean : numpy.ndarray
mean of each gaussian. Shape --> (batch... | [
"Sample",
"from",
"independent",
"mixture",
"of",
"gaussian",
"(",
"MoG",
")",
"distributions"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/reinforcement-learning/dqn/utils.py#L179-L203 | train |
apache/incubator-mxnet | example/nce-loss/nce.py | nce_loss_subwords | def nce_loss_subwords(
data, label, label_mask, label_weight, embed_weight, vocab_size, num_hidden):
"""NCE-Loss layer under subword-units input.
"""
# get subword-units embedding.
label_units_embed = mx.sym.Embedding(data=label,
input_dim=vocab_size,
... | python | def nce_loss_subwords(
data, label, label_mask, label_weight, embed_weight, vocab_size, num_hidden):
"""NCE-Loss layer under subword-units input.
"""
# get subword-units embedding.
label_units_embed = mx.sym.Embedding(data=label,
input_dim=vocab_size,
... | [
"def",
"nce_loss_subwords",
"(",
"data",
",",
"label",
",",
"label_mask",
",",
"label_weight",
",",
"embed_weight",
",",
"vocab_size",
",",
"num_hidden",
")",
":",
"# get subword-units embedding.",
"label_units_embed",
"=",
"mx",
".",
"sym",
".",
"Embedding",
"(",... | NCE-Loss layer under subword-units input. | [
"NCE",
"-",
"Loss",
"layer",
"under",
"subword",
"-",
"units",
"input",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/nce-loss/nce.py#L38-L62 | train |
apache/incubator-mxnet | example/gluon/super_resolution/super_resolution.py | get_dataset | def get_dataset(prefetch=False):
"""Download the BSDS500 dataset and return train and test iters."""
if path.exists(data_dir):
print(
"Directory {} already exists, skipping.\n"
"To force download and extraction, delete the directory and re-run."
"".format(data_dir),
... | python | def get_dataset(prefetch=False):
"""Download the BSDS500 dataset and return train and test iters."""
if path.exists(data_dir):
print(
"Directory {} already exists, skipping.\n"
"To force download and extraction, delete the directory and re-run."
"".format(data_dir),
... | [
"def",
"get_dataset",
"(",
"prefetch",
"=",
"False",
")",
":",
"if",
"path",
".",
"exists",
"(",
"data_dir",
")",
":",
"print",
"(",
"\"Directory {} already exists, skipping.\\n\"",
"\"To force download and extraction, delete the directory and re-run.\"",
"\"\"",
".",
"fo... | Download the BSDS500 dataset and return train and test iters. | [
"Download",
"the",
"BSDS500",
"dataset",
"and",
"return",
"train",
"and",
"test",
"iters",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/gluon/super_resolution/super_resolution.py#L69-L130 | train |
apache/incubator-mxnet | example/rnn/large_word_lm/run_utils.py | evaluate | def evaluate(mod, data_iter, epoch, log_interval):
""" Run evaluation on cpu. """
start = time.time()
total_L = 0.0
nbatch = 0
density = 0
mod.set_states(value=0)
for batch in data_iter:
mod.forward(batch, is_train=False)
outputs = mod.get_outputs(merge_multi_context=False)
... | python | def evaluate(mod, data_iter, epoch, log_interval):
""" Run evaluation on cpu. """
start = time.time()
total_L = 0.0
nbatch = 0
density = 0
mod.set_states(value=0)
for batch in data_iter:
mod.forward(batch, is_train=False)
outputs = mod.get_outputs(merge_multi_context=False)
... | [
"def",
"evaluate",
"(",
"mod",
",",
"data_iter",
",",
"epoch",
",",
"log_interval",
")",
":",
"start",
"=",
"time",
".",
"time",
"(",
")",
"total_L",
"=",
"0.0",
"nbatch",
"=",
"0",
"density",
"=",
"0",
"mod",
".",
"set_states",
"(",
"value",
"=",
... | Run evaluation on cpu. | [
"Run",
"evaluation",
"on",
"cpu",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/rnn/large_word_lm/run_utils.py#L66-L90 | train |
apache/incubator-mxnet | example/fcn-xs/data.py | FileIter._read | def _read(self):
"""get two list, each list contains two elements: name and nd.array value"""
_, data_img_name, label_img_name = self.f.readline().strip('\n').split("\t")
data = {}
label = {}
data[self.data_name], label[self.label_name] = self._read_img(data_img_name, label_img_n... | python | def _read(self):
"""get two list, each list contains two elements: name and nd.array value"""
_, data_img_name, label_img_name = self.f.readline().strip('\n').split("\t")
data = {}
label = {}
data[self.data_name], label[self.label_name] = self._read_img(data_img_name, label_img_n... | [
"def",
"_read",
"(",
"self",
")",
":",
"_",
",",
"data_img_name",
",",
"label_img_name",
"=",
"self",
".",
"f",
".",
"readline",
"(",
")",
".",
"strip",
"(",
"'\\n'",
")",
".",
"split",
"(",
"\"\\t\"",
")",
"data",
"=",
"{",
"}",
"label",
"=",
"{... | get two list, each list contains two elements: name and nd.array value | [
"get",
"two",
"list",
"each",
"list",
"contains",
"two",
"elements",
":",
"name",
"and",
"nd",
".",
"array",
"value"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/fcn-xs/data.py#L64-L70 | train |
apache/incubator-mxnet | example/fcn-xs/data.py | FileIter.next | def next(self):
"""return one dict which contains "data" and "label" """
if self.iter_next():
self.data, self.label = self._read()
return {self.data_name : self.data[0][1],
self.label_name : self.label[0][1]}
else:
raise StopIteration | python | def next(self):
"""return one dict which contains "data" and "label" """
if self.iter_next():
self.data, self.label = self._read()
return {self.data_name : self.data[0][1],
self.label_name : self.label[0][1]}
else:
raise StopIteration | [
"def",
"next",
"(",
"self",
")",
":",
"if",
"self",
".",
"iter_next",
"(",
")",
":",
"self",
".",
"data",
",",
"self",
".",
"label",
"=",
"self",
".",
"_read",
"(",
")",
"return",
"{",
"self",
".",
"data_name",
":",
"self",
".",
"data",
"[",
"0... | return one dict which contains "data" and "label" | [
"return",
"one",
"dict",
"which",
"contains",
"data",
"and",
"label"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/fcn-xs/data.py#L132-L139 | train |
apache/incubator-mxnet | python/mxnet/contrib/onnx/onnx2mx/import_onnx.py | GraphProto._convert_operator | def _convert_operator(self, node_name, op_name, attrs, inputs):
"""Convert from onnx operator to mxnet operator.
The converter must specify conversions explicitly for incompatible name, and
apply handlers to operator attributes.
Parameters
----------
:param node_name : s... | python | def _convert_operator(self, node_name, op_name, attrs, inputs):
"""Convert from onnx operator to mxnet operator.
The converter must specify conversions explicitly for incompatible name, and
apply handlers to operator attributes.
Parameters
----------
:param node_name : s... | [
"def",
"_convert_operator",
"(",
"self",
",",
"node_name",
",",
"op_name",
",",
"attrs",
",",
"inputs",
")",
":",
"if",
"op_name",
"in",
"convert_map",
":",
"op_name",
",",
"new_attrs",
",",
"inputs",
"=",
"convert_map",
"[",
"op_name",
"]",
"(",
"attrs",
... | Convert from onnx operator to mxnet operator.
The converter must specify conversions explicitly for incompatible name, and
apply handlers to operator attributes.
Parameters
----------
:param node_name : str
name of the node to be translated.
:param op_name : ... | [
"Convert",
"from",
"onnx",
"operator",
"to",
"mxnet",
"operator",
".",
"The",
"converter",
"must",
"specify",
"conversions",
"explicitly",
"for",
"incompatible",
"name",
"and",
"apply",
"handlers",
"to",
"operator",
"attributes",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/onnx/onnx2mx/import_onnx.py#L41-L74 | train |
apache/incubator-mxnet | python/mxnet/contrib/onnx/onnx2mx/import_onnx.py | GraphProto.from_onnx | def from_onnx(self, graph):
"""Construct symbol from onnx graph.
Parameters
----------
graph : onnx protobuf object
The loaded onnx graph
Returns
-------
sym :symbol.Symbol
The returned mxnet symbol
params : dict
A dic... | python | def from_onnx(self, graph):
"""Construct symbol from onnx graph.
Parameters
----------
graph : onnx protobuf object
The loaded onnx graph
Returns
-------
sym :symbol.Symbol
The returned mxnet symbol
params : dict
A dic... | [
"def",
"from_onnx",
"(",
"self",
",",
"graph",
")",
":",
"# get input, output shapes",
"self",
".",
"model_metadata",
"=",
"self",
".",
"get_graph_metadata",
"(",
"graph",
")",
"# parse network inputs, aka parameters",
"for",
"init_tensor",
"in",
"graph",
".",
"init... | Construct symbol from onnx graph.
Parameters
----------
graph : onnx protobuf object
The loaded onnx graph
Returns
-------
sym :symbol.Symbol
The returned mxnet symbol
params : dict
A dict of name: nd.array pairs, used as pret... | [
"Construct",
"symbol",
"from",
"onnx",
"graph",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/onnx/onnx2mx/import_onnx.py#L76-L135 | train |
apache/incubator-mxnet | python/mxnet/contrib/onnx/onnx2mx/import_onnx.py | GraphProto.get_graph_metadata | def get_graph_metadata(self, graph):
"""
Get the model metadata from a given onnx graph.
"""
_params = set()
for tensor_vals in graph.initializer:
_params.add(tensor_vals.name)
input_data = []
for graph_input in graph.input:
if graph_input... | python | def get_graph_metadata(self, graph):
"""
Get the model metadata from a given onnx graph.
"""
_params = set()
for tensor_vals in graph.initializer:
_params.add(tensor_vals.name)
input_data = []
for graph_input in graph.input:
if graph_input... | [
"def",
"get_graph_metadata",
"(",
"self",
",",
"graph",
")",
":",
"_params",
"=",
"set",
"(",
")",
"for",
"tensor_vals",
"in",
"graph",
".",
"initializer",
":",
"_params",
".",
"add",
"(",
"tensor_vals",
".",
"name",
")",
"input_data",
"=",
"[",
"]",
"... | Get the model metadata from a given onnx graph. | [
"Get",
"the",
"model",
"metadata",
"from",
"a",
"given",
"onnx",
"graph",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/onnx/onnx2mx/import_onnx.py#L137-L158 | train |
apache/incubator-mxnet | python/mxnet/contrib/onnx/onnx2mx/import_onnx.py | GraphProto.graph_to_gluon | def graph_to_gluon(self, graph, ctx):
"""Construct SymbolBlock from onnx graph.
Parameters
----------
graph : onnx protobuf object
The loaded onnx graph
ctx : Context or list of Context
Loads the model into one or many context(s).
Returns
... | python | def graph_to_gluon(self, graph, ctx):
"""Construct SymbolBlock from onnx graph.
Parameters
----------
graph : onnx protobuf object
The loaded onnx graph
ctx : Context or list of Context
Loads the model into one or many context(s).
Returns
... | [
"def",
"graph_to_gluon",
"(",
"self",
",",
"graph",
",",
"ctx",
")",
":",
"sym",
",",
"arg_params",
",",
"aux_params",
"=",
"self",
".",
"from_onnx",
"(",
"graph",
")",
"metadata",
"=",
"self",
".",
"get_graph_metadata",
"(",
"graph",
")",
"data_names",
... | Construct SymbolBlock from onnx graph.
Parameters
----------
graph : onnx protobuf object
The loaded onnx graph
ctx : Context or list of Context
Loads the model into one or many context(s).
Returns
-------
sym_block :gluon.nn.SymbolBlock
... | [
"Construct",
"SymbolBlock",
"from",
"onnx",
"graph",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/onnx/onnx2mx/import_onnx.py#L160-L191 | train |
apache/incubator-mxnet | python/mxnet/contrib/onnx/onnx2mx/import_onnx.py | GraphProto._parse_array | def _parse_array(self, tensor_proto):
"""Grab data in TensorProto and convert to numpy array."""
try:
from onnx.numpy_helper import to_array
except ImportError:
raise ImportError("Onnx and protobuf need to be installed. "
+ "Instructions to i... | python | def _parse_array(self, tensor_proto):
"""Grab data in TensorProto and convert to numpy array."""
try:
from onnx.numpy_helper import to_array
except ImportError:
raise ImportError("Onnx and protobuf need to be installed. "
+ "Instructions to i... | [
"def",
"_parse_array",
"(",
"self",
",",
"tensor_proto",
")",
":",
"try",
":",
"from",
"onnx",
".",
"numpy_helper",
"import",
"to_array",
"except",
"ImportError",
":",
"raise",
"ImportError",
"(",
"\"Onnx and protobuf need to be installed. \"",
"+",
"\"Instructions to... | Grab data in TensorProto and convert to numpy array. | [
"Grab",
"data",
"in",
"TensorProto",
"and",
"convert",
"to",
"numpy",
"array",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/onnx/onnx2mx/import_onnx.py#L193-L205 | train |
apache/incubator-mxnet | python/mxnet/contrib/onnx/onnx2mx/import_onnx.py | GraphProto._parse_attr | def _parse_attr(self, attr_proto):
"""Convert a list of AttributeProto to a dict, with names as keys."""
attrs = {}
for a in attr_proto:
for f in ['f', 'i', 's']:
if a.HasField(f):
attrs[a.name] = getattr(a, f)
# Needed for supp... | python | def _parse_attr(self, attr_proto):
"""Convert a list of AttributeProto to a dict, with names as keys."""
attrs = {}
for a in attr_proto:
for f in ['f', 'i', 's']:
if a.HasField(f):
attrs[a.name] = getattr(a, f)
# Needed for supp... | [
"def",
"_parse_attr",
"(",
"self",
",",
"attr_proto",
")",
":",
"attrs",
"=",
"{",
"}",
"for",
"a",
"in",
"attr_proto",
":",
"for",
"f",
"in",
"[",
"'f'",
",",
"'i'",
",",
"'s'",
"]",
":",
"if",
"a",
".",
"HasField",
"(",
"f",
")",
":",
"attrs"... | Convert a list of AttributeProto to a dict, with names as keys. | [
"Convert",
"a",
"list",
"of",
"AttributeProto",
"to",
"a",
"dict",
"with",
"names",
"as",
"keys",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/onnx/onnx2mx/import_onnx.py#L207-L229 | train |
apache/incubator-mxnet | python/mxnet/contrib/svrg_optimization/svrg_module.py | SVRGModule.reshape | def reshape(self, data_shapes, label_shapes=None):
"""Reshapes both modules for new input shapes.
Parameters
----------
data_shapes : list of (str, tuple)
Typically is ``data_iter.provide_data``.
label_shapes : list of (str, tuple)
Typically is ``data_ite... | python | def reshape(self, data_shapes, label_shapes=None):
"""Reshapes both modules for new input shapes.
Parameters
----------
data_shapes : list of (str, tuple)
Typically is ``data_iter.provide_data``.
label_shapes : list of (str, tuple)
Typically is ``data_ite... | [
"def",
"reshape",
"(",
"self",
",",
"data_shapes",
",",
"label_shapes",
"=",
"None",
")",
":",
"super",
"(",
"SVRGModule",
",",
"self",
")",
".",
"reshape",
"(",
"data_shapes",
",",
"label_shapes",
"=",
"label_shapes",
")",
"self",
".",
"_mod_aux",
".",
... | Reshapes both modules for new input shapes.
Parameters
----------
data_shapes : list of (str, tuple)
Typically is ``data_iter.provide_data``.
label_shapes : list of (str, tuple)
Typically is ``data_iter.provide_label``. | [
"Reshapes",
"both",
"modules",
"for",
"new",
"input",
"shapes",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/svrg_optimization/svrg_module.py#L101-L112 | train |
apache/incubator-mxnet | python/mxnet/contrib/svrg_optimization/svrg_module.py | SVRGModule.init_optimizer | def init_optimizer(self, kvstore='local', optimizer='sgd',
optimizer_params=(('learning_rate', 0.01),), force_init=False):
"""Installs and initializes SVRGOptimizer. The SVRGOptimizer is a wrapper class for a regular optimizer that is
passed in and a special AssignmentOptimizer to... | python | def init_optimizer(self, kvstore='local', optimizer='sgd',
optimizer_params=(('learning_rate', 0.01),), force_init=False):
"""Installs and initializes SVRGOptimizer. The SVRGOptimizer is a wrapper class for a regular optimizer that is
passed in and a special AssignmentOptimizer to... | [
"def",
"init_optimizer",
"(",
"self",
",",
"kvstore",
"=",
"'local'",
",",
"optimizer",
"=",
"'sgd'",
",",
"optimizer_params",
"=",
"(",
"(",
"'learning_rate'",
",",
"0.01",
")",
",",
")",
",",
"force_init",
"=",
"False",
")",
":",
"# Init dict for storing a... | Installs and initializes SVRGOptimizer. The SVRGOptimizer is a wrapper class for a regular optimizer that is
passed in and a special AssignmentOptimizer to accumulate the full gradients. If KVStore is 'local' or None,
the full gradients will be accumulated locally without pushing to the KVStore. Otherw... | [
"Installs",
"and",
"initializes",
"SVRGOptimizer",
".",
"The",
"SVRGOptimizer",
"is",
"a",
"wrapper",
"class",
"for",
"a",
"regular",
"optimizer",
"that",
"is",
"passed",
"in",
"and",
"a",
"special",
"AssignmentOptimizer",
"to",
"accumulate",
"the",
"full",
"gra... | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/svrg_optimization/svrg_module.py#L114-L151 | train |
apache/incubator-mxnet | python/mxnet/contrib/svrg_optimization/svrg_module.py | SVRGModule._create_optimizer | def _create_optimizer(self, optimizer, default_opt, kvstore, optimizer_params):
"""Helper function to create a svrg optimizer. SVRG optimizer encapsulates two optimizers and
will redirect update() to the correct optimizer based on the key.
Parameters
----------
kvstore : str or ... | python | def _create_optimizer(self, optimizer, default_opt, kvstore, optimizer_params):
"""Helper function to create a svrg optimizer. SVRG optimizer encapsulates two optimizers and
will redirect update() to the correct optimizer based on the key.
Parameters
----------
kvstore : str or ... | [
"def",
"_create_optimizer",
"(",
"self",
",",
"optimizer",
",",
"default_opt",
",",
"kvstore",
",",
"optimizer_params",
")",
":",
"# code partially copied from mxnet module.init_optimizer() to accomodate svrg_optimizer",
"batch_size",
"=",
"self",
".",
"_exec_group",
".",
"... | Helper function to create a svrg optimizer. SVRG optimizer encapsulates two optimizers and
will redirect update() to the correct optimizer based on the key.
Parameters
----------
kvstore : str or KVStore
Default `'local'`.
optimizer: str
Name for SVRGOpti... | [
"Helper",
"function",
"to",
"create",
"a",
"svrg",
"optimizer",
".",
"SVRG",
"optimizer",
"encapsulates",
"two",
"optimizers",
"and",
"will",
"redirect",
"update",
"()",
"to",
"the",
"correct",
"optimizer",
"based",
"on",
"the",
"key",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/svrg_optimization/svrg_module.py#L153-L196 | train |
apache/incubator-mxnet | python/mxnet/contrib/svrg_optimization/svrg_module.py | SVRGModule.bind | def bind(self, data_shapes, label_shapes=None, for_training=True,
inputs_need_grad=False, force_rebind=False, shared_module=None, grad_req='write'):
"""Binds the symbols to construct executors for both two modules. This is necessary before one
can perform computation with the SVRGModule.
... | python | def bind(self, data_shapes, label_shapes=None, for_training=True,
inputs_need_grad=False, force_rebind=False, shared_module=None, grad_req='write'):
"""Binds the symbols to construct executors for both two modules. This is necessary before one
can perform computation with the SVRGModule.
... | [
"def",
"bind",
"(",
"self",
",",
"data_shapes",
",",
"label_shapes",
"=",
"None",
",",
"for_training",
"=",
"True",
",",
"inputs_need_grad",
"=",
"False",
",",
"force_rebind",
"=",
"False",
",",
"shared_module",
"=",
"None",
",",
"grad_req",
"=",
"'write'",
... | Binds the symbols to construct executors for both two modules. This is necessary before one
can perform computation with the SVRGModule.
Parameters
----------
data_shapes : list of (str, tuple)
Typically is ``data_iter.provide_data``.
label_shapes : list of (str, tup... | [
"Binds",
"the",
"symbols",
"to",
"construct",
"executors",
"for",
"both",
"two",
"modules",
".",
"This",
"is",
"necessary",
"before",
"one",
"can",
"perform",
"computation",
"with",
"the",
"SVRGModule",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/svrg_optimization/svrg_module.py#L198-L230 | train |
apache/incubator-mxnet | python/mxnet/contrib/svrg_optimization/svrg_module.py | SVRGModule.forward | def forward(self, data_batch, is_train=None):
"""Forward computation for both two modules. It supports data batches with different shapes, such as
different batch sizes or different image sizes.
If reshaping of data batch relates to modification of symbol or module, such as
changing imag... | python | def forward(self, data_batch, is_train=None):
"""Forward computation for both two modules. It supports data batches with different shapes, such as
different batch sizes or different image sizes.
If reshaping of data batch relates to modification of symbol or module, such as
changing imag... | [
"def",
"forward",
"(",
"self",
",",
"data_batch",
",",
"is_train",
"=",
"None",
")",
":",
"super",
"(",
"SVRGModule",
",",
"self",
")",
".",
"forward",
"(",
"data_batch",
",",
"is_train",
")",
"if",
"is_train",
":",
"self",
".",
"_mod_aux",
".",
"forwa... | Forward computation for both two modules. It supports data batches with different shapes, such as
different batch sizes or different image sizes.
If reshaping of data batch relates to modification of symbol or module, such as
changing image layout ordering or switching from training to predictin... | [
"Forward",
"computation",
"for",
"both",
"two",
"modules",
".",
"It",
"supports",
"data",
"batches",
"with",
"different",
"shapes",
"such",
"as",
"different",
"batch",
"sizes",
"or",
"different",
"image",
"sizes",
".",
"If",
"reshaping",
"of",
"data",
"batch",... | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/svrg_optimization/svrg_module.py#L232-L253 | train |
apache/incubator-mxnet | python/mxnet/contrib/svrg_optimization/svrg_module.py | SVRGModule.backward | def backward(self, out_grads=None):
"""Backward computation.
See Also
----------
:meth:`BaseModule.backward`.
Parameters
----------
out_grads : NDArray or list of NDArray, optional
Gradient on the outputs to be propagated back.
This param... | python | def backward(self, out_grads=None):
"""Backward computation.
See Also
----------
:meth:`BaseModule.backward`.
Parameters
----------
out_grads : NDArray or list of NDArray, optional
Gradient on the outputs to be propagated back.
This param... | [
"def",
"backward",
"(",
"self",
",",
"out_grads",
"=",
"None",
")",
":",
"super",
"(",
"SVRGModule",
",",
"self",
")",
".",
"backward",
"(",
"out_grads",
")",
"if",
"self",
".",
"_mod_aux",
".",
"binded",
":",
"self",
".",
"_mod_aux",
".",
"backward",
... | Backward computation.
See Also
----------
:meth:`BaseModule.backward`.
Parameters
----------
out_grads : NDArray or list of NDArray, optional
Gradient on the outputs to be propagated back.
This parameter is only needed when bind is called
... | [
"Backward",
"computation",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/svrg_optimization/svrg_module.py#L255-L272 | train |
apache/incubator-mxnet | python/mxnet/contrib/svrg_optimization/svrg_module.py | SVRGModule.update_full_grads | def update_full_grads(self, train_data):
"""Computes the gradients over all data w.r.t weights of past
m epochs. For distributed env, it will accumulate full grads in the kvstore.
Parameters
----------
train_data: DataIter
Train data iterator
"""
para... | python | def update_full_grads(self, train_data):
"""Computes the gradients over all data w.r.t weights of past
m epochs. For distributed env, it will accumulate full grads in the kvstore.
Parameters
----------
train_data: DataIter
Train data iterator
"""
para... | [
"def",
"update_full_grads",
"(",
"self",
",",
"train_data",
")",
":",
"param_names",
"=",
"self",
".",
"_exec_group",
".",
"param_names",
"arg",
",",
"aux",
"=",
"self",
".",
"get_params",
"(",
")",
"self",
".",
"_mod_aux",
".",
"set_params",
"(",
"arg_par... | Computes the gradients over all data w.r.t weights of past
m epochs. For distributed env, it will accumulate full grads in the kvstore.
Parameters
----------
train_data: DataIter
Train data iterator | [
"Computes",
"the",
"gradients",
"over",
"all",
"data",
"w",
".",
"r",
".",
"t",
"weights",
"of",
"past",
"m",
"epochs",
".",
"For",
"distributed",
"env",
"it",
"will",
"accumulate",
"full",
"grads",
"in",
"the",
"kvstore",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/svrg_optimization/svrg_module.py#L292-L325 | train |
apache/incubator-mxnet | python/mxnet/contrib/svrg_optimization/svrg_module.py | SVRGModule._accumulate_kvstore | def _accumulate_kvstore(self, key, value):
"""Accumulate gradients over all data in the KVStore. In distributed setting, each worker sees a portion of
data. The full gradients will be aggregated from each worker in the KVStore.
Parameters
----------
key: int or str
... | python | def _accumulate_kvstore(self, key, value):
"""Accumulate gradients over all data in the KVStore. In distributed setting, each worker sees a portion of
data. The full gradients will be aggregated from each worker in the KVStore.
Parameters
----------
key: int or str
... | [
"def",
"_accumulate_kvstore",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"# Accumulate full gradients for current epochs",
"self",
".",
"_kvstore",
".",
"push",
"(",
"key",
"+",
"\"_full\"",
",",
"value",
")",
"self",
".",
"_kvstore",
".",
"_barrier",
"(... | Accumulate gradients over all data in the KVStore. In distributed setting, each worker sees a portion of
data. The full gradients will be aggregated from each worker in the KVStore.
Parameters
----------
key: int or str
Key in the KVStore.
value: NDArray, RowSparseN... | [
"Accumulate",
"gradients",
"over",
"all",
"data",
"in",
"the",
"KVStore",
".",
"In",
"distributed",
"setting",
"each",
"worker",
"sees",
"a",
"portion",
"of",
"data",
".",
"The",
"full",
"gradients",
"will",
"be",
"aggregated",
"from",
"each",
"worker",
"in"... | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/svrg_optimization/svrg_module.py#L327-L344 | train |
apache/incubator-mxnet | python/mxnet/contrib/svrg_optimization/svrg_module.py | SVRGModule._allocate_gradients | def _allocate_gradients(self, key, value):
"""Allocate average of full gradients accumulated in the KVStore to each device.
Parameters
----------
key: int or str
Key in the kvstore.
value: List of NDArray, List of RowSparseNDArray
A list of average of th... | python | def _allocate_gradients(self, key, value):
"""Allocate average of full gradients accumulated in the KVStore to each device.
Parameters
----------
key: int or str
Key in the kvstore.
value: List of NDArray, List of RowSparseNDArray
A list of average of th... | [
"def",
"_allocate_gradients",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"_ctx_len",
")",
":",
"self",
".",
"_param_dict",
"[",
"i",
"]",
"[",
"key",
"]",
"=",
"value",
"[",
"i",
"]",
"/",
"self"... | Allocate average of full gradients accumulated in the KVStore to each device.
Parameters
----------
key: int or str
Key in the kvstore.
value: List of NDArray, List of RowSparseNDArray
A list of average of the full gradients in the KVStore. | [
"Allocate",
"average",
"of",
"full",
"gradients",
"accumulated",
"in",
"the",
"KVStore",
"to",
"each",
"device",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/svrg_optimization/svrg_module.py#L346-L358 | train |
apache/incubator-mxnet | python/mxnet/contrib/svrg_optimization/svrg_module.py | SVRGModule._svrg_grads_update_rule | def _svrg_grads_update_rule(self, g_curr_batch_curr_weight, g_curr_batch_special_weight,
g_special_weight_all_batch):
"""Calculates the gradient based on the SVRG update rule.
Parameters
----------
g_curr_batch_curr_weight : NDArray
gradients o... | python | def _svrg_grads_update_rule(self, g_curr_batch_curr_weight, g_curr_batch_special_weight,
g_special_weight_all_batch):
"""Calculates the gradient based on the SVRG update rule.
Parameters
----------
g_curr_batch_curr_weight : NDArray
gradients o... | [
"def",
"_svrg_grads_update_rule",
"(",
"self",
",",
"g_curr_batch_curr_weight",
",",
"g_curr_batch_special_weight",
",",
"g_special_weight_all_batch",
")",
":",
"for",
"index",
",",
"grad",
"in",
"enumerate",
"(",
"g_curr_batch_curr_weight",
")",
":",
"grad",
"-=",
"g... | Calculates the gradient based on the SVRG update rule.
Parameters
----------
g_curr_batch_curr_weight : NDArray
gradients of current weight of self.mod w.r.t current batch of data
g_curr_batch_special_weight: NDArray
gradients of the weight of past m epochs of sel... | [
"Calculates",
"the",
"gradient",
"based",
"on",
"the",
"SVRG",
"update",
"rule",
".",
"Parameters",
"----------",
"g_curr_batch_curr_weight",
":",
"NDArray",
"gradients",
"of",
"current",
"weight",
"of",
"self",
".",
"mod",
"w",
".",
"r",
".",
"t",
"current",
... | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/svrg_optimization/svrg_module.py#L360-L380 | train |
apache/incubator-mxnet | python/mxnet/contrib/svrg_optimization/svrg_module.py | SVRGModule._update_svrg_gradients | def _update_svrg_gradients(self):
"""Calculates gradients based on the SVRG update rule.
"""
param_names = self._exec_group.param_names
for ctx in range(self._ctx_len):
for index, name in enumerate(param_names):
g_curr_batch_reg = self._exec_group.grad_arrays[... | python | def _update_svrg_gradients(self):
"""Calculates gradients based on the SVRG update rule.
"""
param_names = self._exec_group.param_names
for ctx in range(self._ctx_len):
for index, name in enumerate(param_names):
g_curr_batch_reg = self._exec_group.grad_arrays[... | [
"def",
"_update_svrg_gradients",
"(",
"self",
")",
":",
"param_names",
"=",
"self",
".",
"_exec_group",
".",
"param_names",
"for",
"ctx",
"in",
"range",
"(",
"self",
".",
"_ctx_len",
")",
":",
"for",
"index",
",",
"name",
"in",
"enumerate",
"(",
"param_nam... | Calculates gradients based on the SVRG update rule. | [
"Calculates",
"gradients",
"based",
"on",
"the",
"SVRG",
"update",
"rule",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/svrg_optimization/svrg_module.py#L382-L393 | train |
apache/incubator-mxnet | python/mxnet/contrib/svrg_optimization/svrg_module.py | SVRGModule.fit | def fit(self, train_data, eval_data=None, eval_metric='acc',
epoch_end_callback=None, batch_end_callback=None, kvstore='local',
optimizer='sgd', optimizer_params=(('learning_rate', 0.01),),
eval_end_callback=None,
eval_batch_end_callback=None, initializer=mx.init.Uniform(... | python | def fit(self, train_data, eval_data=None, eval_metric='acc',
epoch_end_callback=None, batch_end_callback=None, kvstore='local',
optimizer='sgd', optimizer_params=(('learning_rate', 0.01),),
eval_end_callback=None,
eval_batch_end_callback=None, initializer=mx.init.Uniform(... | [
"def",
"fit",
"(",
"self",
",",
"train_data",
",",
"eval_data",
"=",
"None",
",",
"eval_metric",
"=",
"'acc'",
",",
"epoch_end_callback",
"=",
"None",
",",
"batch_end_callback",
"=",
"None",
",",
"kvstore",
"=",
"'local'",
",",
"optimizer",
"=",
"'sgd'",
"... | Trains the module parameters.
Parameters
----------
train_data : DataIter
Train DataIter.
eval_data : DataIter
If not ``None``, will be used as validation set and the performance
after each epoch will be evaluated.
eval_metric : str or EvalMet... | [
"Trains",
"the",
"module",
"parameters",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/svrg_optimization/svrg_module.py#L395-L552 | train |
apache/incubator-mxnet | python/mxnet/contrib/svrg_optimization/svrg_module.py | SVRGModule.prepare | def prepare(self, data_batch, sparse_row_id_fn=None):
"""Prepares two modules for processing a data batch.
Usually involves switching bucket and reshaping.
For modules that contain `row_sparse` parameters in KVStore,
it prepares the `row_sparse` parameters based on the sparse_row_id_fn.... | python | def prepare(self, data_batch, sparse_row_id_fn=None):
"""Prepares two modules for processing a data batch.
Usually involves switching bucket and reshaping.
For modules that contain `row_sparse` parameters in KVStore,
it prepares the `row_sparse` parameters based on the sparse_row_id_fn.... | [
"def",
"prepare",
"(",
"self",
",",
"data_batch",
",",
"sparse_row_id_fn",
"=",
"None",
")",
":",
"super",
"(",
"SVRGModule",
",",
"self",
")",
".",
"prepare",
"(",
"data_batch",
",",
"sparse_row_id_fn",
"=",
"sparse_row_id_fn",
")",
"self",
".",
"_mod_aux",... | Prepares two modules for processing a data batch.
Usually involves switching bucket and reshaping.
For modules that contain `row_sparse` parameters in KVStore,
it prepares the `row_sparse` parameters based on the sparse_row_id_fn.
When KVStore is used to update parameters for multi-dev... | [
"Prepares",
"two",
"modules",
"for",
"processing",
"a",
"data",
"batch",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/svrg_optimization/svrg_module.py#L554-L579 | train |
apache/incubator-mxnet | example/ssd/dataset/yolo_format.py | YoloFormat._load_image_set_index | def _load_image_set_index(self, shuffle):
"""
find out which indexes correspond to given image set (train or val)
Parameters:
----------
shuffle : boolean
whether to shuffle the image list
Returns:
----------
entire list of images specified in... | python | def _load_image_set_index(self, shuffle):
"""
find out which indexes correspond to given image set (train or val)
Parameters:
----------
shuffle : boolean
whether to shuffle the image list
Returns:
----------
entire list of images specified in... | [
"def",
"_load_image_set_index",
"(",
"self",
",",
"shuffle",
")",
":",
"assert",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"list_file",
")",
",",
"'Path does not exists: {}'",
".",
"format",
"(",
"self",
".",
"list_file",
")",
"with",
"open",
"("... | find out which indexes correspond to given image set (train or val)
Parameters:
----------
shuffle : boolean
whether to shuffle the image list
Returns:
----------
entire list of images specified in the setting | [
"find",
"out",
"which",
"indexes",
"correspond",
"to",
"given",
"image",
"set",
"(",
"train",
"or",
"val",
")"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/dataset/yolo_format.py#L72-L89 | train |
apache/incubator-mxnet | example/ssd/dataset/yolo_format.py | YoloFormat._label_path_from_index | def _label_path_from_index(self, index):
"""
given image index, find out annotation path
Parameters:
----------
index: int
index of a specific image
Returns:
----------
full path of annotation file
"""
label_file = os.path.joi... | python | def _label_path_from_index(self, index):
"""
given image index, find out annotation path
Parameters:
----------
index: int
index of a specific image
Returns:
----------
full path of annotation file
"""
label_file = os.path.joi... | [
"def",
"_label_path_from_index",
"(",
"self",
",",
"index",
")",
":",
"label_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"label_dir",
",",
"index",
"+",
"self",
".",
"label_extension",
")",
"assert",
"os",
".",
"path",
".",
"exists",
... | given image index, find out annotation path
Parameters:
----------
index: int
index of a specific image
Returns:
----------
full path of annotation file | [
"given",
"image",
"index",
"find",
"out",
"annotation",
"path"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/dataset/yolo_format.py#L124-L139 | train |
apache/incubator-mxnet | example/ssd/dataset/yolo_format.py | YoloFormat._load_image_labels | def _load_image_labels(self):
"""
preprocess all ground-truths
Returns:
----------
labels packed in [num_images x max_num_objects x 5] tensor
"""
temp = []
# load ground-truths
for idx in self.image_set_index:
label_file = self._label... | python | def _load_image_labels(self):
"""
preprocess all ground-truths
Returns:
----------
labels packed in [num_images x max_num_objects x 5] tensor
"""
temp = []
# load ground-truths
for idx in self.image_set_index:
label_file = self._label... | [
"def",
"_load_image_labels",
"(",
"self",
")",
":",
"temp",
"=",
"[",
"]",
"# load ground-truths",
"for",
"idx",
"in",
"self",
".",
"image_set_index",
":",
"label_file",
"=",
"self",
".",
"_label_path_from_index",
"(",
"idx",
")",
"with",
"open",
"(",
"label... | preprocess all ground-truths
Returns:
----------
labels packed in [num_images x max_num_objects x 5] tensor | [
"preprocess",
"all",
"ground",
"-",
"truths"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/dataset/yolo_format.py#L141-L170 | train |
apache/incubator-mxnet | python/mxnet/registry.py | get_register_func | def get_register_func(base_class, nickname):
"""Get registrator function.
Parameters
----------
base_class : type
base class for classes that will be reigstered
nickname : str
nickname of base_class for logging
Returns
-------
a registrator function
"""
if base_... | python | def get_register_func(base_class, nickname):
"""Get registrator function.
Parameters
----------
base_class : type
base class for classes that will be reigstered
nickname : str
nickname of base_class for logging
Returns
-------
a registrator function
"""
if base_... | [
"def",
"get_register_func",
"(",
"base_class",
",",
"nickname",
")",
":",
"if",
"base_class",
"not",
"in",
"_REGISTRY",
":",
"_REGISTRY",
"[",
"base_class",
"]",
"=",
"{",
"}",
"registry",
"=",
"_REGISTRY",
"[",
"base_class",
"]",
"def",
"register",
"(",
"... | Get registrator function.
Parameters
----------
base_class : type
base class for classes that will be reigstered
nickname : str
nickname of base_class for logging
Returns
-------
a registrator function | [
"Get",
"registrator",
"function",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/registry.py#L49-L85 | train |
apache/incubator-mxnet | python/mxnet/registry.py | get_alias_func | def get_alias_func(base_class, nickname):
"""Get registrator function that allow aliases.
Parameters
----------
base_class : type
base class for classes that will be reigstered
nickname : str
nickname of base_class for logging
Returns
-------
a registrator function
... | python | def get_alias_func(base_class, nickname):
"""Get registrator function that allow aliases.
Parameters
----------
base_class : type
base class for classes that will be reigstered
nickname : str
nickname of base_class for logging
Returns
-------
a registrator function
... | [
"def",
"get_alias_func",
"(",
"base_class",
",",
"nickname",
")",
":",
"register",
"=",
"get_register_func",
"(",
"base_class",
",",
"nickname",
")",
"def",
"alias",
"(",
"*",
"aliases",
")",
":",
"\"\"\"alias registrator\"\"\"",
"def",
"reg",
"(",
"klass",
")... | Get registrator function that allow aliases.
Parameters
----------
base_class : type
base class for classes that will be reigstered
nickname : str
nickname of base_class for logging
Returns
-------
a registrator function | [
"Get",
"registrator",
"function",
"that",
"allow",
"aliases",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/registry.py#L88-L112 | train |
apache/incubator-mxnet | python/mxnet/registry.py | get_create_func | def get_create_func(base_class, nickname):
"""Get creator function
Parameters
----------
base_class : type
base class for classes that will be reigstered
nickname : str
nickname of base_class for logging
Returns
-------
a creator function
"""
if base_class not i... | python | def get_create_func(base_class, nickname):
"""Get creator function
Parameters
----------
base_class : type
base class for classes that will be reigstered
nickname : str
nickname of base_class for logging
Returns
-------
a creator function
"""
if base_class not i... | [
"def",
"get_create_func",
"(",
"base_class",
",",
"nickname",
")",
":",
"if",
"base_class",
"not",
"in",
"_REGISTRY",
":",
"_REGISTRY",
"[",
"base_class",
"]",
"=",
"{",
"}",
"registry",
"=",
"_REGISTRY",
"[",
"base_class",
"]",
"def",
"create",
"(",
"*",
... | Get creator function
Parameters
----------
base_class : type
base class for classes that will be reigstered
nickname : str
nickname of base_class for logging
Returns
-------
a creator function | [
"Get",
"creator",
"function"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/registry.py#L115-L176 | train |
apache/incubator-mxnet | tools/diagnose.py | parse_args | def parse_args():
"""Parse arguments."""
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='Diagnose script for checking the current system.')
choices = ['python', 'pip', 'mxnet', 'os', 'hardware', 'network']
for choice in choices:
... | python | def parse_args():
"""Parse arguments."""
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='Diagnose script for checking the current system.')
choices = ['python', 'pip', 'mxnet', 'os', 'hardware', 'network']
for choice in choices:
... | [
"def",
"parse_args",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"formatter_class",
"=",
"argparse",
".",
"ArgumentDefaultsHelpFormatter",
",",
"description",
"=",
"'Diagnose script for checking the current system.'",
")",
"choices",
"=",
"[",
... | Parse arguments. | [
"Parse",
"arguments",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/tools/diagnose.py#L33-L48 | train |
apache/incubator-mxnet | example/cnn_text_classification/data_helpers.py | clean_str | def clean_str(string):
"""Tokenization/string cleaning for all datasets except for SST.
Original taken from https://github.com/yoonkim/CNN_sentence/blob/master/process_data.py
"""
string = re.sub(r"[^A-Za-z0-9(),!?\'\`]", " ", string)
string = re.sub(r"\'s", " \'s", string)
string = re.sub(r"\'v... | python | def clean_str(string):
"""Tokenization/string cleaning for all datasets except for SST.
Original taken from https://github.com/yoonkim/CNN_sentence/blob/master/process_data.py
"""
string = re.sub(r"[^A-Za-z0-9(),!?\'\`]", " ", string)
string = re.sub(r"\'s", " \'s", string)
string = re.sub(r"\'v... | [
"def",
"clean_str",
"(",
"string",
")",
":",
"string",
"=",
"re",
".",
"sub",
"(",
"r\"[^A-Za-z0-9(),!?\\'\\`]\"",
",",
"\" \"",
",",
"string",
")",
"string",
"=",
"re",
".",
"sub",
"(",
"r\"\\'s\"",
",",
"\" \\'s\"",
",",
"string",
")",
"string",
"=",
... | Tokenization/string cleaning for all datasets except for SST.
Original taken from https://github.com/yoonkim/CNN_sentence/blob/master/process_data.py | [
"Tokenization",
"/",
"string",
"cleaning",
"for",
"all",
"datasets",
"except",
"for",
"SST",
".",
"Original",
"taken",
"from",
"https",
":",
"//",
"github",
".",
"com",
"/",
"yoonkim",
"/",
"CNN_sentence",
"/",
"blob",
"/",
"master",
"/",
"process_data",
"... | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/cnn_text_classification/data_helpers.py#L33-L50 | train |
apache/incubator-mxnet | example/cnn_text_classification/data_helpers.py | load_data_and_labels | def load_data_and_labels():
"""Loads MR polarity data from files, splits the data into words and generates labels.
Returns split sentences and labels.
"""
# Load data from files
pos_path = "./data/rt-polaritydata/rt-polarity.pos"
neg_path = "./data/rt-polaritydata/rt-polarity.neg"
if not os.... | python | def load_data_and_labels():
"""Loads MR polarity data from files, splits the data into words and generates labels.
Returns split sentences and labels.
"""
# Load data from files
pos_path = "./data/rt-polaritydata/rt-polarity.pos"
neg_path = "./data/rt-polaritydata/rt-polarity.neg"
if not os.... | [
"def",
"load_data_and_labels",
"(",
")",
":",
"# Load data from files",
"pos_path",
"=",
"\"./data/rt-polaritydata/rt-polarity.pos\"",
"neg_path",
"=",
"\"./data/rt-polaritydata/rt-polarity.neg\"",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"pos_path",
")",
":",
... | Loads MR polarity data from files, splits the data into words and generates labels.
Returns split sentences and labels. | [
"Loads",
"MR",
"polarity",
"data",
"from",
"files",
"splits",
"the",
"data",
"into",
"words",
"and",
"generates",
"labels",
".",
"Returns",
"split",
"sentences",
"and",
"labels",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/cnn_text_classification/data_helpers.py#L53-L76 | train |
apache/incubator-mxnet | example/cnn_text_classification/data_helpers.py | pad_sentences | def pad_sentences(sentences, padding_word="</s>"):
"""Pads all sentences to the same length. The length is defined by the longest sentence.
Returns padded sentences.
"""
sequence_length = max(len(x) for x in sentences)
padded_sentences = []
for i, sentence in enumerate(sentences):
num_pa... | python | def pad_sentences(sentences, padding_word="</s>"):
"""Pads all sentences to the same length. The length is defined by the longest sentence.
Returns padded sentences.
"""
sequence_length = max(len(x) for x in sentences)
padded_sentences = []
for i, sentence in enumerate(sentences):
num_pa... | [
"def",
"pad_sentences",
"(",
"sentences",
",",
"padding_word",
"=",
"\"</s>\"",
")",
":",
"sequence_length",
"=",
"max",
"(",
"len",
"(",
"x",
")",
"for",
"x",
"in",
"sentences",
")",
"padded_sentences",
"=",
"[",
"]",
"for",
"i",
",",
"sentence",
"in",
... | Pads all sentences to the same length. The length is defined by the longest sentence.
Returns padded sentences. | [
"Pads",
"all",
"sentences",
"to",
"the",
"same",
"length",
".",
"The",
"length",
"is",
"defined",
"by",
"the",
"longest",
"sentence",
".",
"Returns",
"padded",
"sentences",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/cnn_text_classification/data_helpers.py#L79-L89 | train |
apache/incubator-mxnet | example/cnn_text_classification/data_helpers.py | build_input_data | def build_input_data(sentences, labels, vocabulary):
"""Maps sentencs and labels to vectors based on a vocabulary."""
x = np.array([[vocabulary[word] for word in sentence] for sentence in sentences])
y = np.array(labels)
return [x, y] | python | def build_input_data(sentences, labels, vocabulary):
"""Maps sentencs and labels to vectors based on a vocabulary."""
x = np.array([[vocabulary[word] for word in sentence] for sentence in sentences])
y = np.array(labels)
return [x, y] | [
"def",
"build_input_data",
"(",
"sentences",
",",
"labels",
",",
"vocabulary",
")",
":",
"x",
"=",
"np",
".",
"array",
"(",
"[",
"[",
"vocabulary",
"[",
"word",
"]",
"for",
"word",
"in",
"sentence",
"]",
"for",
"sentence",
"in",
"sentences",
"]",
")",
... | Maps sentencs and labels to vectors based on a vocabulary. | [
"Maps",
"sentencs",
"and",
"labels",
"to",
"vectors",
"based",
"on",
"a",
"vocabulary",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/cnn_text_classification/data_helpers.py#L105-L109 | train |
apache/incubator-mxnet | example/cnn_text_classification/data_helpers.py | build_input_data_with_word2vec | def build_input_data_with_word2vec(sentences, labels, word2vec_list):
"""
Map sentences and labels to vectors based on a pretrained word2vec
"""
x_vec = []
for sent in sentences:
vec = []
for word in sent:
if word in word2vec_list:
vec.append(word2vec_list... | python | def build_input_data_with_word2vec(sentences, labels, word2vec_list):
"""
Map sentences and labels to vectors based on a pretrained word2vec
"""
x_vec = []
for sent in sentences:
vec = []
for word in sent:
if word in word2vec_list:
vec.append(word2vec_list... | [
"def",
"build_input_data_with_word2vec",
"(",
"sentences",
",",
"labels",
",",
"word2vec_list",
")",
":",
"x_vec",
"=",
"[",
"]",
"for",
"sent",
"in",
"sentences",
":",
"vec",
"=",
"[",
"]",
"for",
"word",
"in",
"sent",
":",
"if",
"word",
"in",
"word2vec... | Map sentences and labels to vectors based on a pretrained word2vec | [
"Map",
"sentences",
"and",
"labels",
"to",
"vectors",
"based",
"on",
"a",
"pretrained",
"word2vec"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/cnn_text_classification/data_helpers.py#L112-L127 | train |
apache/incubator-mxnet | example/cnn_text_classification/data_helpers.py | load_data_with_word2vec | def load_data_with_word2vec(word2vec_list):
"""Loads and preprocessed data for the MR dataset.
Returns input vectors, labels, vocabulary, and inverse vocabulary.
"""
# Load and preprocess data
sentences, labels = load_data_and_labels()
sentences_padded = pad_sentences(sentences)
# vocabulary... | python | def load_data_with_word2vec(word2vec_list):
"""Loads and preprocessed data for the MR dataset.
Returns input vectors, labels, vocabulary, and inverse vocabulary.
"""
# Load and preprocess data
sentences, labels = load_data_and_labels()
sentences_padded = pad_sentences(sentences)
# vocabulary... | [
"def",
"load_data_with_word2vec",
"(",
"word2vec_list",
")",
":",
"# Load and preprocess data",
"sentences",
",",
"labels",
"=",
"load_data_and_labels",
"(",
")",
"sentences_padded",
"=",
"pad_sentences",
"(",
"sentences",
")",
"# vocabulary, vocabulary_inv = build_vocab(sent... | Loads and preprocessed data for the MR dataset.
Returns input vectors, labels, vocabulary, and inverse vocabulary. | [
"Loads",
"and",
"preprocessed",
"data",
"for",
"the",
"MR",
"dataset",
".",
"Returns",
"input",
"vectors",
"labels",
"vocabulary",
"and",
"inverse",
"vocabulary",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/cnn_text_classification/data_helpers.py#L130-L138 | train |
apache/incubator-mxnet | example/cnn_text_classification/data_helpers.py | load_data | def load_data():
"""Loads and preprocessed data for the MR dataset.
Returns input vectors, labels, vocabulary, and inverse vocabulary.
"""
# Load and preprocess data
sentences, labels = load_data_and_labels()
sentences_padded = pad_sentences(sentences)
vocabulary, vocabulary_inv = build_voca... | python | def load_data():
"""Loads and preprocessed data for the MR dataset.
Returns input vectors, labels, vocabulary, and inverse vocabulary.
"""
# Load and preprocess data
sentences, labels = load_data_and_labels()
sentences_padded = pad_sentences(sentences)
vocabulary, vocabulary_inv = build_voca... | [
"def",
"load_data",
"(",
")",
":",
"# Load and preprocess data",
"sentences",
",",
"labels",
"=",
"load_data_and_labels",
"(",
")",
"sentences_padded",
"=",
"pad_sentences",
"(",
"sentences",
")",
"vocabulary",
",",
"vocabulary_inv",
"=",
"build_vocab",
"(",
"senten... | Loads and preprocessed data for the MR dataset.
Returns input vectors, labels, vocabulary, and inverse vocabulary. | [
"Loads",
"and",
"preprocessed",
"data",
"for",
"the",
"MR",
"dataset",
".",
"Returns",
"input",
"vectors",
"labels",
"vocabulary",
"and",
"inverse",
"vocabulary",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/cnn_text_classification/data_helpers.py#L141-L150 | train |
apache/incubator-mxnet | example/cnn_text_classification/data_helpers.py | batch_iter | def batch_iter(data, batch_size, num_epochs):
"""Generates a batch iterator for a dataset."""
data = np.array(data)
data_size = len(data)
num_batches_per_epoch = int(len(data)/batch_size) + 1
for epoch in range(num_epochs):
# Shuffle the data at each epoch
shuffle_indices = np.random... | python | def batch_iter(data, batch_size, num_epochs):
"""Generates a batch iterator for a dataset."""
data = np.array(data)
data_size = len(data)
num_batches_per_epoch = int(len(data)/batch_size) + 1
for epoch in range(num_epochs):
# Shuffle the data at each epoch
shuffle_indices = np.random... | [
"def",
"batch_iter",
"(",
"data",
",",
"batch_size",
",",
"num_epochs",
")",
":",
"data",
"=",
"np",
".",
"array",
"(",
"data",
")",
"data_size",
"=",
"len",
"(",
"data",
")",
"num_batches_per_epoch",
"=",
"int",
"(",
"len",
"(",
"data",
")",
"/",
"b... | Generates a batch iterator for a dataset. | [
"Generates",
"a",
"batch",
"iterator",
"for",
"a",
"dataset",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/cnn_text_classification/data_helpers.py#L153-L165 | train |
apache/incubator-mxnet | example/cnn_text_classification/data_helpers.py | load_pretrained_word2vec | def load_pretrained_word2vec(infile):
"""Load the pre-trained word2vec from file."""
if isinstance(infile, str):
infile = open(infile)
word2vec_list = {}
for idx, line in enumerate(infile):
if idx == 0:
vocab_size, dim = line.strip().split()
else:
tks = l... | python | def load_pretrained_word2vec(infile):
"""Load the pre-trained word2vec from file."""
if isinstance(infile, str):
infile = open(infile)
word2vec_list = {}
for idx, line in enumerate(infile):
if idx == 0:
vocab_size, dim = line.strip().split()
else:
tks = l... | [
"def",
"load_pretrained_word2vec",
"(",
"infile",
")",
":",
"if",
"isinstance",
"(",
"infile",
",",
"str",
")",
":",
"infile",
"=",
"open",
"(",
"infile",
")",
"word2vec_list",
"=",
"{",
"}",
"for",
"idx",
",",
"line",
"in",
"enumerate",
"(",
"infile",
... | Load the pre-trained word2vec from file. | [
"Load",
"the",
"pre",
"-",
"trained",
"word2vec",
"from",
"file",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/cnn_text_classification/data_helpers.py#L168-L181 | train |
apache/incubator-mxnet | example/rcnn/symdata/loader.py | generate_batch | def generate_batch(im_tensor, im_info):
"""return batch"""
data = [im_tensor, im_info]
data_shapes = [('data', im_tensor.shape), ('im_info', im_info.shape)]
data_batch = mx.io.DataBatch(data=data, label=None, provide_data=data_shapes, provide_label=None)
return data_batch | python | def generate_batch(im_tensor, im_info):
"""return batch"""
data = [im_tensor, im_info]
data_shapes = [('data', im_tensor.shape), ('im_info', im_info.shape)]
data_batch = mx.io.DataBatch(data=data, label=None, provide_data=data_shapes, provide_label=None)
return data_batch | [
"def",
"generate_batch",
"(",
"im_tensor",
",",
"im_info",
")",
":",
"data",
"=",
"[",
"im_tensor",
",",
"im_info",
"]",
"data_shapes",
"=",
"[",
"(",
"'data'",
",",
"im_tensor",
".",
"shape",
")",
",",
"(",
"'im_info'",
",",
"im_info",
".",
"shape",
"... | return batch | [
"return",
"batch"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/rcnn/symdata/loader.py#L44-L49 | train |
apache/incubator-mxnet | example/ssd/symbol/vgg16_reduced.py | get_symbol | def get_symbol(num_classes=1000, **kwargs):
"""
VGG 16 layers network
This is a modified version, with fc6/fc7 layers replaced by conv layers
And the network is slightly smaller than original VGG 16 network
"""
data = mx.symbol.Variable(name="data")
label = mx.symbol.Variable(name="label")
... | python | def get_symbol(num_classes=1000, **kwargs):
"""
VGG 16 layers network
This is a modified version, with fc6/fc7 layers replaced by conv layers
And the network is slightly smaller than original VGG 16 network
"""
data = mx.symbol.Variable(name="data")
label = mx.symbol.Variable(name="label")
... | [
"def",
"get_symbol",
"(",
"num_classes",
"=",
"1000",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"mx",
".",
"symbol",
".",
"Variable",
"(",
"name",
"=",
"\"data\"",
")",
"label",
"=",
"mx",
".",
"symbol",
".",
"Variable",
"(",
"name",
"=",
"\"... | VGG 16 layers network
This is a modified version, with fc6/fc7 layers replaced by conv layers
And the network is slightly smaller than original VGG 16 network | [
"VGG",
"16",
"layers",
"network",
"This",
"is",
"a",
"modified",
"version",
"with",
"fc6",
"/",
"fc7",
"layers",
"replaced",
"by",
"conv",
"layers",
"And",
"the",
"network",
"is",
"slightly",
"smaller",
"than",
"original",
"VGG",
"16",
"network"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/symbol/vgg16_reduced.py#L20-L103 | train |
apache/incubator-mxnet | example/caffe/caffe_net.py | get_mlp | def get_mlp():
"""Get multi-layer perceptron"""
data = mx.symbol.Variable('data')
fc1 = mx.symbol.CaffeOp(data_0=data, num_weight=2, name='fc1',
prototxt="layer{type:\"InnerProduct\" inner_product_param{num_output: 128} }")
act1 = mx.symbol.CaffeOp(data_0=fc1, prototxt="layer... | python | def get_mlp():
"""Get multi-layer perceptron"""
data = mx.symbol.Variable('data')
fc1 = mx.symbol.CaffeOp(data_0=data, num_weight=2, name='fc1',
prototxt="layer{type:\"InnerProduct\" inner_product_param{num_output: 128} }")
act1 = mx.symbol.CaffeOp(data_0=fc1, prototxt="layer... | [
"def",
"get_mlp",
"(",
")",
":",
"data",
"=",
"mx",
".",
"symbol",
".",
"Variable",
"(",
"'data'",
")",
"fc1",
"=",
"mx",
".",
"symbol",
".",
"CaffeOp",
"(",
"data_0",
"=",
"data",
",",
"num_weight",
"=",
"2",
",",
"name",
"=",
"'fc1'",
",",
"pro... | Get multi-layer perceptron | [
"Get",
"multi",
"-",
"layer",
"perceptron"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/caffe/caffe_net.py#L25-L42 | train |
apache/incubator-mxnet | example/caffe/caffe_net.py | get_lenet | def get_lenet():
"""LeCun, Yann, Leon Bottou, Yoshua Bengio, and Patrick
Haffner. "Gradient-based learning applied to document recognition."
Proceedings of the IEEE (1998)
"""
data = mx.symbol.Variable('data')
# first conv
conv1 = mx.symbol.CaffeOp(data_0=data, num_weight=2,
... | python | def get_lenet():
"""LeCun, Yann, Leon Bottou, Yoshua Bengio, and Patrick
Haffner. "Gradient-based learning applied to document recognition."
Proceedings of the IEEE (1998)
"""
data = mx.symbol.Variable('data')
# first conv
conv1 = mx.symbol.CaffeOp(data_0=data, num_weight=2,
... | [
"def",
"get_lenet",
"(",
")",
":",
"data",
"=",
"mx",
".",
"symbol",
".",
"Variable",
"(",
"'data'",
")",
"# first conv",
"conv1",
"=",
"mx",
".",
"symbol",
".",
"CaffeOp",
"(",
"data_0",
"=",
"data",
",",
"num_weight",
"=",
"2",
",",
"prototxt",
"="... | LeCun, Yann, Leon Bottou, Yoshua Bengio, and Patrick
Haffner. "Gradient-based learning applied to document recognition."
Proceedings of the IEEE (1998) | [
"LeCun",
"Yann",
"Leon",
"Bottou",
"Yoshua",
"Bengio",
"and",
"Patrick",
"Haffner",
".",
"Gradient",
"-",
"based",
"learning",
"applied",
"to",
"document",
"recognition",
".",
"Proceedings",
"of",
"the",
"IEEE",
"(",
"1998",
")"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/caffe/caffe_net.py#L45-L81 | train |
apache/incubator-mxnet | example/caffe/caffe_net.py | parse_args | def parse_args():
"""Parse the arguments"""
parser = argparse.ArgumentParser(description='train an image classifier on mnist')
parser.add_argument('--network', type=str, default='lenet',
help='the cnn to use (mlp | lenet | <path to network json file>')
parser.add_argument('--caff... | python | def parse_args():
"""Parse the arguments"""
parser = argparse.ArgumentParser(description='train an image classifier on mnist')
parser.add_argument('--network', type=str, default='lenet',
help='the cnn to use (mlp | lenet | <path to network json file>')
parser.add_argument('--caff... | [
"def",
"parse_args",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'train an image classifier on mnist'",
")",
"parser",
".",
"add_argument",
"(",
"'--network'",
",",
"type",
"=",
"str",
",",
"default",
"=",
"'lenet'"... | Parse the arguments | [
"Parse",
"the",
"arguments"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/caffe/caffe_net.py#L89-L122 | train |
apache/incubator-mxnet | example/sparse/linear_classification/weighted_softmax_ce.py | WeightedSoftmaxCrossEntropyLoss.forward | def forward(self, is_train, req, in_data, out_data, aux):
"""Implements forward computation.
is_train : bool, whether forwarding for training or testing.
req : list of {'null', 'write', 'inplace', 'add'}, how to assign to out_data. 'null' means skip assignment, etc.
in_data : list of ND... | python | def forward(self, is_train, req, in_data, out_data, aux):
"""Implements forward computation.
is_train : bool, whether forwarding for training or testing.
req : list of {'null', 'write', 'inplace', 'add'}, how to assign to out_data. 'null' means skip assignment, etc.
in_data : list of ND... | [
"def",
"forward",
"(",
"self",
",",
"is_train",
",",
"req",
",",
"in_data",
",",
"out_data",
",",
"aux",
")",
":",
"data",
"=",
"in_data",
"[",
"0",
"]",
"label",
"=",
"in_data",
"[",
"1",
"]",
"pred",
"=",
"mx",
".",
"nd",
".",
"SoftmaxOutput",
... | Implements forward computation.
is_train : bool, whether forwarding for training or testing.
req : list of {'null', 'write', 'inplace', 'add'}, how to assign to out_data. 'null' means skip assignment, etc.
in_data : list of NDArray, input data.
out_data : list of NDArray, pre-allocated ... | [
"Implements",
"forward",
"computation",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/sparse/linear_classification/weighted_softmax_ce.py#L30-L42 | train |
apache/incubator-mxnet | example/sparse/linear_classification/weighted_softmax_ce.py | WeightedSoftmaxCrossEntropyLoss.backward | def backward(self, req, out_grad, in_data, out_data, in_grad, aux):
"""Implements backward computation
req : list of {'null', 'write', 'inplace', 'add'}, how to assign to in_grad
out_grad : list of NDArray, gradient w.r.t. output data.
in_grad : list of NDArray, gradient w.r.t. input da... | python | def backward(self, req, out_grad, in_data, out_data, in_grad, aux):
"""Implements backward computation
req : list of {'null', 'write', 'inplace', 'add'}, how to assign to in_grad
out_grad : list of NDArray, gradient w.r.t. output data.
in_grad : list of NDArray, gradient w.r.t. input da... | [
"def",
"backward",
"(",
"self",
",",
"req",
",",
"out_grad",
",",
"in_data",
",",
"out_data",
",",
"in_grad",
",",
"aux",
")",
":",
"label",
"=",
"in_data",
"[",
"1",
"]",
"pred",
"=",
"out_data",
"[",
"0",
"]",
"dx",
"=",
"pred",
"-",
"mx",
".",... | Implements backward computation
req : list of {'null', 'write', 'inplace', 'add'}, how to assign to in_grad
out_grad : list of NDArray, gradient w.r.t. output data.
in_grad : list of NDArray, gradient w.r.t. input data. This is the output buffer. | [
"Implements",
"backward",
"computation"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/sparse/linear_classification/weighted_softmax_ce.py#L44-L57 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule._reset_bind | def _reset_bind(self):
"""Internal utility function to reset binding."""
self.binded = False
self._buckets = {}
self._curr_module = None
self._curr_bucket_key = None | python | def _reset_bind(self):
"""Internal utility function to reset binding."""
self.binded = False
self._buckets = {}
self._curr_module = None
self._curr_bucket_key = None | [
"def",
"_reset_bind",
"(",
"self",
")",
":",
"self",
".",
"binded",
"=",
"False",
"self",
".",
"_buckets",
"=",
"{",
"}",
"self",
".",
"_curr_module",
"=",
"None",
"self",
".",
"_curr_bucket_key",
"=",
"None"
] | Internal utility function to reset binding. | [
"Internal",
"utility",
"function",
"to",
"reset",
"binding",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L100-L105 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.data_names | def data_names(self):
"""A list of names for data required by this module."""
if self.binded:
return self._curr_module.data_names
else:
_, data_names, _ = self._call_sym_gen(self._default_bucket_key)
return data_names | python | def data_names(self):
"""A list of names for data required by this module."""
if self.binded:
return self._curr_module.data_names
else:
_, data_names, _ = self._call_sym_gen(self._default_bucket_key)
return data_names | [
"def",
"data_names",
"(",
"self",
")",
":",
"if",
"self",
".",
"binded",
":",
"return",
"self",
".",
"_curr_module",
".",
"data_names",
"else",
":",
"_",
",",
"data_names",
",",
"_",
"=",
"self",
".",
"_call_sym_gen",
"(",
"self",
".",
"_default_bucket_k... | A list of names for data required by this module. | [
"A",
"list",
"of",
"names",
"for",
"data",
"required",
"by",
"this",
"module",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L112-L118 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.output_names | def output_names(self):
"""A list of names for the outputs of this module."""
if self.binded:
return self._curr_module.output_names
else:
symbol, _, _ = self._call_sym_gen(self._default_bucket_key)
return symbol.list_outputs() | python | def output_names(self):
"""A list of names for the outputs of this module."""
if self.binded:
return self._curr_module.output_names
else:
symbol, _, _ = self._call_sym_gen(self._default_bucket_key)
return symbol.list_outputs() | [
"def",
"output_names",
"(",
"self",
")",
":",
"if",
"self",
".",
"binded",
":",
"return",
"self",
".",
"_curr_module",
".",
"output_names",
"else",
":",
"symbol",
",",
"_",
",",
"_",
"=",
"self",
".",
"_call_sym_gen",
"(",
"self",
".",
"_default_bucket_k... | A list of names for the outputs of this module. | [
"A",
"list",
"of",
"names",
"for",
"the",
"outputs",
"of",
"this",
"module",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L121-L127 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.get_params | def get_params(self):
"""Gets current parameters.
Returns
-------
`(arg_params, aux_params)`
A pair of dictionaries each mapping parameter names to NDArray values.
"""
assert self.binded and self.params_initialized
self._curr_module._params_dirty = se... | python | def get_params(self):
"""Gets current parameters.
Returns
-------
`(arg_params, aux_params)`
A pair of dictionaries each mapping parameter names to NDArray values.
"""
assert self.binded and self.params_initialized
self._curr_module._params_dirty = se... | [
"def",
"get_params",
"(",
"self",
")",
":",
"assert",
"self",
".",
"binded",
"and",
"self",
".",
"params_initialized",
"self",
".",
"_curr_module",
".",
"_params_dirty",
"=",
"self",
".",
"_params_dirty",
"params",
"=",
"self",
".",
"_curr_module",
".",
"get... | Gets current parameters.
Returns
-------
`(arg_params, aux_params)`
A pair of dictionaries each mapping parameter names to NDArray values. | [
"Gets",
"current",
"parameters",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L165-L177 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.init_params | def init_params(self, initializer=Uniform(0.01), arg_params=None, aux_params=None,
allow_missing=False, force_init=False, allow_extra=False):
"""Initializes parameters.
Parameters
----------
initializer : Initializer
arg_params : dict
Defaults to ... | python | def init_params(self, initializer=Uniform(0.01), arg_params=None, aux_params=None,
allow_missing=False, force_init=False, allow_extra=False):
"""Initializes parameters.
Parameters
----------
initializer : Initializer
arg_params : dict
Defaults to ... | [
"def",
"init_params",
"(",
"self",
",",
"initializer",
"=",
"Uniform",
"(",
"0.01",
")",
",",
"arg_params",
"=",
"None",
",",
"aux_params",
"=",
"None",
",",
"allow_missing",
"=",
"False",
",",
"force_init",
"=",
"False",
",",
"allow_extra",
"=",
"False",
... | Initializes parameters.
Parameters
----------
initializer : Initializer
arg_params : dict
Defaults to ``None``. Existing parameters. This has higher priority
than `initializer`.
aux_params : dict
Defaults to ``None``. Existing auxiliary states... | [
"Initializes",
"parameters",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L222-L252 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.get_states | def get_states(self, merge_multi_context=True):
"""Gets states from all devices.
Parameters
----------
merge_multi_context : bool
Default is `True`. In the case when data-parallelism is used, the states
will be collected from multiple devices. A `True` value indi... | python | def get_states(self, merge_multi_context=True):
"""Gets states from all devices.
Parameters
----------
merge_multi_context : bool
Default is `True`. In the case when data-parallelism is used, the states
will be collected from multiple devices. A `True` value indi... | [
"def",
"get_states",
"(",
"self",
",",
"merge_multi_context",
"=",
"True",
")",
":",
"assert",
"self",
".",
"binded",
"and",
"self",
".",
"params_initialized",
"return",
"self",
".",
"_curr_module",
".",
"get_states",
"(",
"merge_multi_context",
"=",
"merge_mult... | Gets states from all devices.
Parameters
----------
merge_multi_context : bool
Default is `True`. In the case when data-parallelism is used, the states
will be collected from multiple devices. A `True` value indicate that we
should merge the collected results... | [
"Gets",
"states",
"from",
"all",
"devices",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L254-L273 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.set_states | def set_states(self, states=None, value=None):
"""Sets value for states. Only one of states & values can be specified.
Parameters
----------
states : list of list of NDArrays
Source states arrays formatted like ``[[state1_dev1, state1_dev2],
[state2_dev1, state2_... | python | def set_states(self, states=None, value=None):
"""Sets value for states. Only one of states & values can be specified.
Parameters
----------
states : list of list of NDArrays
Source states arrays formatted like ``[[state1_dev1, state1_dev2],
[state2_dev1, state2_... | [
"def",
"set_states",
"(",
"self",
",",
"states",
"=",
"None",
",",
"value",
"=",
"None",
")",
":",
"assert",
"self",
".",
"binded",
"and",
"self",
".",
"params_initialized",
"self",
".",
"_curr_module",
".",
"set_states",
"(",
"states",
",",
"value",
")"... | Sets value for states. Only one of states & values can be specified.
Parameters
----------
states : list of list of NDArrays
Source states arrays formatted like ``[[state1_dev1, state1_dev2],
[state2_dev1, state2_dev2]]``.
value : number
A single scal... | [
"Sets",
"value",
"for",
"states",
".",
"Only",
"one",
"of",
"states",
"&",
"values",
"can",
"be",
"specified",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L275-L287 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.bind | def bind(self, data_shapes, label_shapes=None, for_training=True,
inputs_need_grad=False, force_rebind=False, shared_module=None,
grad_req='write'):
"""Binding for a `BucketingModule` means setting up the buckets and binding the
executor for the default bucket key. Executors co... | python | def bind(self, data_shapes, label_shapes=None, for_training=True,
inputs_need_grad=False, force_rebind=False, shared_module=None,
grad_req='write'):
"""Binding for a `BucketingModule` means setting up the buckets and binding the
executor for the default bucket key. Executors co... | [
"def",
"bind",
"(",
"self",
",",
"data_shapes",
",",
"label_shapes",
"=",
"None",
",",
"for_training",
"=",
"True",
",",
"inputs_need_grad",
"=",
"False",
",",
"force_rebind",
"=",
"False",
",",
"shared_module",
"=",
"None",
",",
"grad_req",
"=",
"'write'",
... | Binding for a `BucketingModule` means setting up the buckets and binding the
executor for the default bucket key. Executors corresponding to other keys are
bound afterwards with `switch_bucket`.
Parameters
----------
data_shapes : list of (str, tuple)
This should cor... | [
"Binding",
"for",
"a",
"BucketingModule",
"means",
"setting",
"up",
"the",
"buckets",
"and",
"binding",
"the",
"executor",
"for",
"the",
"default",
"bucket",
"key",
".",
"Executors",
"corresponding",
"to",
"other",
"keys",
"are",
"bound",
"afterwards",
"with",
... | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L289-L352 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.switch_bucket | def switch_bucket(self, bucket_key, data_shapes, label_shapes=None):
"""Switches to a different bucket. This will change ``self.curr_module``.
Parameters
----------
bucket_key : str (or any python object)
The key of the target bucket.
data_shapes : list of (str, tupl... | python | def switch_bucket(self, bucket_key, data_shapes, label_shapes=None):
"""Switches to a different bucket. This will change ``self.curr_module``.
Parameters
----------
bucket_key : str (or any python object)
The key of the target bucket.
data_shapes : list of (str, tupl... | [
"def",
"switch_bucket",
"(",
"self",
",",
"bucket_key",
",",
"data_shapes",
",",
"label_shapes",
"=",
"None",
")",
":",
"assert",
"self",
".",
"binded",
",",
"'call bind before switching bucket'",
"if",
"not",
"bucket_key",
"in",
"self",
".",
"_buckets",
":",
... | Switches to a different bucket. This will change ``self.curr_module``.
Parameters
----------
bucket_key : str (or any python object)
The key of the target bucket.
data_shapes : list of (str, tuple)
Typically ``data_batch.provide_data``.
label_shapes : lis... | [
"Switches",
"to",
"a",
"different",
"bucket",
".",
"This",
"will",
"change",
"self",
".",
"curr_module",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L354-L385 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.init_optimizer | def init_optimizer(self, kvstore='local', optimizer='sgd',
optimizer_params=(('learning_rate', 0.01),),
force_init=False):
"""Installs and initializes optimizers.
Parameters
----------
kvstore : str or KVStore
Defaults to `'local... | python | def init_optimizer(self, kvstore='local', optimizer='sgd',
optimizer_params=(('learning_rate', 0.01),),
force_init=False):
"""Installs and initializes optimizers.
Parameters
----------
kvstore : str or KVStore
Defaults to `'local... | [
"def",
"init_optimizer",
"(",
"self",
",",
"kvstore",
"=",
"'local'",
",",
"optimizer",
"=",
"'sgd'",
",",
"optimizer_params",
"=",
"(",
"(",
"'learning_rate'",
",",
"0.01",
")",
",",
")",
",",
"force_init",
"=",
"False",
")",
":",
"assert",
"self",
".",... | Installs and initializes optimizers.
Parameters
----------
kvstore : str or KVStore
Defaults to `'local'`.
optimizer : str or Optimizer
Defaults to `'sgd'`
optimizer_params : dict
Defaults to `(('learning_rate', 0.01),)`. The default value is ... | [
"Installs",
"and",
"initializes",
"optimizers",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L387-L416 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.prepare | def prepare(self, data_batch, sparse_row_id_fn=None):
'''Prepares the module for processing a data batch.
Usually involves switching bucket and reshaping.
For modules that contain `row_sparse` parameters in KVStore,
it prepares the `row_sparse` parameters based on the sparse_row_id_fn.
... | python | def prepare(self, data_batch, sparse_row_id_fn=None):
'''Prepares the module for processing a data batch.
Usually involves switching bucket and reshaping.
For modules that contain `row_sparse` parameters in KVStore,
it prepares the `row_sparse` parameters based on the sparse_row_id_fn.
... | [
"def",
"prepare",
"(",
"self",
",",
"data_batch",
",",
"sparse_row_id_fn",
"=",
"None",
")",
":",
"# perform bind if haven't done so",
"assert",
"self",
".",
"binded",
"and",
"self",
".",
"params_initialized",
"bucket_key",
"=",
"data_batch",
".",
"bucket_key",
"o... | Prepares the module for processing a data batch.
Usually involves switching bucket and reshaping.
For modules that contain `row_sparse` parameters in KVStore,
it prepares the `row_sparse` parameters based on the sparse_row_id_fn.
Parameters
----------
data_batch : DataB... | [
"Prepares",
"the",
"module",
"for",
"processing",
"a",
"data",
"batch",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L418-L445 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.forward | def forward(self, data_batch, is_train=None):
"""Forward computation.
Parameters
----------
data_batch : DataBatch
is_train : bool
Defaults to ``None``, in which case `is_train` is take as ``self.for_training``.
"""
assert self.binded and self.params_... | python | def forward(self, data_batch, is_train=None):
"""Forward computation.
Parameters
----------
data_batch : DataBatch
is_train : bool
Defaults to ``None``, in which case `is_train` is take as ``self.for_training``.
"""
assert self.binded and self.params_... | [
"def",
"forward",
"(",
"self",
",",
"data_batch",
",",
"is_train",
"=",
"None",
")",
":",
"assert",
"self",
".",
"binded",
"and",
"self",
".",
"params_initialized",
"self",
".",
"switch_bucket",
"(",
"data_batch",
".",
"bucket_key",
",",
"data_batch",
".",
... | Forward computation.
Parameters
----------
data_batch : DataBatch
is_train : bool
Defaults to ``None``, in which case `is_train` is take as ``self.for_training``. | [
"Forward",
"computation",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L447-L459 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.backward | def backward(self, out_grads=None):
"""Backward computation."""
assert self.binded and self.params_initialized
self._curr_module.backward(out_grads=out_grads) | python | def backward(self, out_grads=None):
"""Backward computation."""
assert self.binded and self.params_initialized
self._curr_module.backward(out_grads=out_grads) | [
"def",
"backward",
"(",
"self",
",",
"out_grads",
"=",
"None",
")",
":",
"assert",
"self",
".",
"binded",
"and",
"self",
".",
"params_initialized",
"self",
".",
"_curr_module",
".",
"backward",
"(",
"out_grads",
"=",
"out_grads",
")"
] | Backward computation. | [
"Backward",
"computation",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L461-L464 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.update | def update(self):
"""Updates parameters according to installed optimizer and the gradient computed
in the previous forward-backward cycle.
When KVStore is used to update parameters for multi-device or multi-machine training,
a copy of the parameters are stored in KVStore. Note that for ... | python | def update(self):
"""Updates parameters according to installed optimizer and the gradient computed
in the previous forward-backward cycle.
When KVStore is used to update parameters for multi-device or multi-machine training,
a copy of the parameters are stored in KVStore. Note that for ... | [
"def",
"update",
"(",
"self",
")",
":",
"assert",
"self",
".",
"binded",
"and",
"self",
".",
"params_initialized",
"and",
"self",
".",
"optimizer_initialized",
"self",
".",
"_params_dirty",
"=",
"True",
"self",
".",
"_curr_module",
".",
"update",
"(",
")"
] | Updates parameters according to installed optimizer and the gradient computed
in the previous forward-backward cycle.
When KVStore is used to update parameters for multi-device or multi-machine training,
a copy of the parameters are stored in KVStore. Note that for `row_sparse` parameters,
... | [
"Updates",
"parameters",
"according",
"to",
"installed",
"optimizer",
"and",
"the",
"gradient",
"computed",
"in",
"the",
"previous",
"forward",
"-",
"backward",
"cycle",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L466-L479 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.get_outputs | def get_outputs(self, merge_multi_context=True):
"""Gets outputs from a previous forward computation.
Parameters
----------
merge_multi_context : bool
Defaults to ``True``. In the case when data-parallelism is used, the outputs
will be collected from multiple dev... | python | def get_outputs(self, merge_multi_context=True):
"""Gets outputs from a previous forward computation.
Parameters
----------
merge_multi_context : bool
Defaults to ``True``. In the case when data-parallelism is used, the outputs
will be collected from multiple dev... | [
"def",
"get_outputs",
"(",
"self",
",",
"merge_multi_context",
"=",
"True",
")",
":",
"assert",
"self",
".",
"binded",
"and",
"self",
".",
"params_initialized",
"return",
"self",
".",
"_curr_module",
".",
"get_outputs",
"(",
"merge_multi_context",
"=",
"merge_mu... | Gets outputs from a previous forward computation.
Parameters
----------
merge_multi_context : bool
Defaults to ``True``. In the case when data-parallelism is used, the outputs
will be collected from multiple devices. A ``True`` value indicate that we
should m... | [
"Gets",
"outputs",
"from",
"a",
"previous",
"forward",
"computation",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L481-L500 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.get_input_grads | def get_input_grads(self, merge_multi_context=True):
"""Gets the gradients with respect to the inputs of the module.
Parameters
----------
merge_multi_context : bool
Defaults to ``True``. In the case when data-parallelism is used, the outputs
will be collected fr... | python | def get_input_grads(self, merge_multi_context=True):
"""Gets the gradients with respect to the inputs of the module.
Parameters
----------
merge_multi_context : bool
Defaults to ``True``. In the case when data-parallelism is used, the outputs
will be collected fr... | [
"def",
"get_input_grads",
"(",
"self",
",",
"merge_multi_context",
"=",
"True",
")",
":",
"assert",
"self",
".",
"binded",
"and",
"self",
".",
"params_initialized",
"and",
"self",
".",
"inputs_need_grad",
"return",
"self",
".",
"_curr_module",
".",
"get_input_gr... | Gets the gradients with respect to the inputs of the module.
Parameters
----------
merge_multi_context : bool
Defaults to ``True``. In the case when data-parallelism is used, the outputs
will be collected from multiple devices. A ``True`` value indicate that we
... | [
"Gets",
"the",
"gradients",
"with",
"respect",
"to",
"the",
"inputs",
"of",
"the",
"module",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L502-L521 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.update_metric | def update_metric(self, eval_metric, labels, pre_sliced=False):
"""Evaluates and accumulates evaluation metric on outputs of the last forward computation.
Parameters
----------
eval_metric : EvalMetric
labels : list of NDArray
Typically ``data_batch.label``.
... | python | def update_metric(self, eval_metric, labels, pre_sliced=False):
"""Evaluates and accumulates evaluation metric on outputs of the last forward computation.
Parameters
----------
eval_metric : EvalMetric
labels : list of NDArray
Typically ``data_batch.label``.
... | [
"def",
"update_metric",
"(",
"self",
",",
"eval_metric",
",",
"labels",
",",
"pre_sliced",
"=",
"False",
")",
":",
"assert",
"self",
".",
"binded",
"and",
"self",
".",
"params_initialized",
"self",
".",
"_curr_module",
".",
"update_metric",
"(",
"eval_metric",... | Evaluates and accumulates evaluation metric on outputs of the last forward computation.
Parameters
----------
eval_metric : EvalMetric
labels : list of NDArray
Typically ``data_batch.label``. | [
"Evaluates",
"and",
"accumulates",
"evaluation",
"metric",
"on",
"outputs",
"of",
"the",
"last",
"forward",
"computation",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L523-L533 | train |
apache/incubator-mxnet | python/mxnet/module/bucketing_module.py | BucketingModule.install_monitor | def install_monitor(self, mon):
"""Installs monitor on all executors """
assert self.binded
self._monitor = mon
for mod in self._buckets.values():
mod.install_monitor(mon) | python | def install_monitor(self, mon):
"""Installs monitor on all executors """
assert self.binded
self._monitor = mon
for mod in self._buckets.values():
mod.install_monitor(mon) | [
"def",
"install_monitor",
"(",
"self",
",",
"mon",
")",
":",
"assert",
"self",
".",
"binded",
"self",
".",
"_monitor",
"=",
"mon",
"for",
"mod",
"in",
"self",
".",
"_buckets",
".",
"values",
"(",
")",
":",
"mod",
".",
"install_monitor",
"(",
"mon",
"... | Installs monitor on all executors | [
"Installs",
"monitor",
"on",
"all",
"executors"
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/module/bucketing_module.py#L541-L546 | train |
apache/incubator-mxnet | python/mxnet/autograd.py | set_recording | def set_recording(is_recording): #pylint: disable=redefined-outer-name
"""Set status to recording/not recording. When recording, graph will be constructed
for gradient computation.
Parameters
----------
is_recording: bool
Returns
-------
previous state before this set.
"""
prev... | python | def set_recording(is_recording): #pylint: disable=redefined-outer-name
"""Set status to recording/not recording. When recording, graph will be constructed
for gradient computation.
Parameters
----------
is_recording: bool
Returns
-------
previous state before this set.
"""
prev... | [
"def",
"set_recording",
"(",
"is_recording",
")",
":",
"#pylint: disable=redefined-outer-name",
"prev",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"check_call",
"(",
"_LIB",
".",
"MXAutogradSetIsRecording",
"(",
"ctypes",
".",
"c_int",
"(",
"is_recording",
")",
",",
... | Set status to recording/not recording. When recording, graph will be constructed
for gradient computation.
Parameters
----------
is_recording: bool
Returns
-------
previous state before this set. | [
"Set",
"status",
"to",
"recording",
"/",
"not",
"recording",
".",
"When",
"recording",
"graph",
"will",
"be",
"constructed",
"for",
"gradient",
"computation",
"."
] | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/autograd.py#L35-L50 | train |
apache/incubator-mxnet | python/mxnet/autograd.py | set_training | def set_training(train_mode): #pylint: disable=redefined-outer-name
"""Set status to training/predicting. This affects ctx.is_train in operator
running context. For example, Dropout will drop inputs randomly when
train_mode=True while simply passing through if train_mode=False.
Parameters
---------... | python | def set_training(train_mode): #pylint: disable=redefined-outer-name
"""Set status to training/predicting. This affects ctx.is_train in operator
running context. For example, Dropout will drop inputs randomly when
train_mode=True while simply passing through if train_mode=False.
Parameters
---------... | [
"def",
"set_training",
"(",
"train_mode",
")",
":",
"#pylint: disable=redefined-outer-name",
"prev",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"check_call",
"(",
"_LIB",
".",
"MXAutogradSetIsTraining",
"(",
"ctypes",
".",
"c_int",
"(",
"train_mode",
")",
",",
"ctyp... | Set status to training/predicting. This affects ctx.is_train in operator
running context. For example, Dropout will drop inputs randomly when
train_mode=True while simply passing through if train_mode=False.
Parameters
----------
train_mode: bool
Returns
-------
previous state before t... | [
"Set",
"status",
"to",
"training",
"/",
"predicting",
".",
"This",
"affects",
"ctx",
".",
"is_train",
"in",
"operator",
"running",
"context",
".",
"For",
"example",
"Dropout",
"will",
"drop",
"inputs",
"randomly",
"when",
"train_mode",
"=",
"True",
"while",
... | 1af29e9c060a4c7d60eeaacba32afdb9a7775ba7 | https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/autograd.py#L52-L68 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.