Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 0a83a6f

Browse files
committed
address comments
1 parent ccf3c54 commit 0a83a6f

5 files changed

Lines changed: 11 additions & 13 deletions

File tree

python/mxnet/gluon/contrib/data/vision/transforms/bbox/bbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def forward(self, img, bbox):
277277
if isinstance(self._fill, numeric_types):
278278
dst = F.full(shape=(oh, ow, c), val=self._fill, dtype=img.dtype)
279279
else:
280-
fill = F.array(self._fill, dtype=img.dtype, ctx=img.context)
280+
fill = F.array(self._fill, dtype=img.dtype, ctx=img.ctx)
281281
if not c == fill.size:
282282
raise ValueError("Channel and fill size mismatch, {} vs {}".format(c, fill.size))
283283
dst = F.tile(fill.reshape((1, c)), reps=(oh * ow, 1)).reshape((oh, ow, c))

python/mxnet/image/image.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -656,14 +656,14 @@ def imrotate(src, rotation_degrees, zoom_in=False, zoom_out=False):
656656
# when a scalar is passed we wrap it into an array
657657
if isinstance(rotation_degrees, Number):
658658
rotation_degrees = nd.array([rotation_degrees] * len(src),
659-
ctx=src.context)
659+
ctx=src.ctx)
660660

661661
if len(src) != len(rotation_degrees):
662662
raise ValueError(
663663
"The number of images must be equal to the number of rotation angles"
664664
)
665665

666-
rotation_degrees = rotation_degrees.as_in_context(src.context)
666+
rotation_degrees = rotation_degrees.as_in_context(src.ctx)
667667
rotation_rad = np.pi * rotation_degrees / 180
668668
# reshape the rotations angle in order to be broadcasted
669669
# over the `src` tensor
@@ -674,10 +674,10 @@ def imrotate(src, rotation_degrees, zoom_in=False, zoom_out=False):
674674
hscale = (float(h - 1) / 2)
675675
wscale = (float(w - 1) / 2)
676676
h_matrix = (
677-
nd.repeat(nd.arange(h, ctx=src.context).astype('float32').reshape(h, 1), w, axis=1) - hscale
677+
nd.repeat(nd.arange(h, ctx=src.ctx).astype('float32').reshape(h, 1), w, axis=1) - hscale
678678
).expand_dims(axis=0)
679679
w_matrix = (
680-
nd.repeat(nd.arange(w, ctx=src.context).astype('float32').reshape(1, w), h, axis=0) - wscale
680+
nd.repeat(nd.arange(w, ctx=src.ctx).astype('float32').reshape(1, w), h, axis=0) - wscale
681681
).expand_dims(axis=0)
682682
# perform rotation on the grid
683683
c_alpha = nd.cos(rotation_rad)
@@ -689,7 +689,7 @@ def imrotate(src, rotation_degrees, zoom_in=False, zoom_out=False):
689689
w_matrix_rot = w_matrix_rot / wscale
690690
h_matrix_rot = h_matrix_rot / hscale
691691

692-
h, w = nd.array([h], ctx=src.context), nd.array([w], ctx=src.context)
692+
h, w = nd.array([h], ctx=src.ctx), nd.array([w], ctx=src.ctx)
693693
# compute the scale factor in case `zoom_in` or `zoom_out` are True
694694
if zoom_in or zoom_out:
695695
rho_corner = nd.sqrt(h * h + w * w)

python/mxnet/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def assert_almost_equal(a, b, rtol=None, atol=None, names=('a', 'b'), equal_nan=
584584
atol = get_atol(atol)
585585
use_np_allclose = isinstance(a, np.ndarray) and isinstance(b, np.ndarray)
586586
if not use_np_allclose:
587-
if not (hasattr(a, 'context') and hasattr(b, 'context') and a.context == b.context and a.dtype == b.dtype):
587+
if not (hasattr(a, 'ctx') and hasattr(b, 'ctx') and a.ctx == b.ctx and a.dtype == b.dtype):
588588
use_np_allclose = True
589589
if isinstance(a, mx.nd.NDArray):
590590
a = a.asnumpy()

src/io/iter_prefetcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class PrefetcherIter : public IIterator<DataBatch> {
9999
// copy data over
100100
for (size_t i = 0; i < batch.data.size(); ++i) {
101101
if ((*dptr)->data.at(i).shape() != batch.data[i].shape_) {
102-
// perf warning, dynamic buffer might be slow
102+
// TODO(zhreshold): memory pool for dynamic shaped data
103103
(*dptr)->data.at(i).ReshapeAndAlloc(batch.data[i].shape_);
104104
}
105105
CHECK_EQ((*dptr)->data.at(i).shape(), batch.data[i].shape_);

src/io/iter_sampler.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class SequentialSampler : public IIterator<DataInst> {
5656
param_.InitAllowUnknown(kwargs);
5757
indices_.resize(param_.length);
5858
std::iota(std::begin(indices_), std::end(indices_), 0); // fill like arange
59-
out_.data.resize(2); // label required by DataBatch, we can use fake label here
60-
out_.data[1] = TBlob(indices_.data(), TShape({1, }), cpu::kDevMask, 0);
59+
out_.data.resize(1);
6160
}
6261

6362
virtual void BeforeFirst(void) {
@@ -129,8 +128,7 @@ class RandomSampler : public IIterator<DataInst> {
129128
mshadow::Random<cpu> *ctx_rng = ResourceManager::Get()->Request(
130129
Context::CPU(), ResourceRequest::kRandom).get_random<cpu, real_t>(nullptr);
131130
rng_.reset(new common::RANDOM_ENGINE(ctx_rng->GetSeed() + param_.seed));
132-
out_.data.resize(2); // label required by DataBatch, we can use fake label here
133-
out_.data[1] = TBlob(indices_.data(), TShape({1, }), cpu::kDevMask, 0);
131+
out_.data.resize(1);
134132
BeforeFirst();
135133
}
136134

@@ -164,7 +162,7 @@ class RandomSampler : public IIterator<DataInst> {
164162
/*! \brief data for next value */
165163
DataInst out_;
166164
/*! \brief random generator engine */
167-
std::unique_ptr<common::RANDOM_ENGINE> rng_;
165+
std::unique_ptr<std::mt19937> rng_;
168166
/*! \brief arguments */
169167
RandomSamplerParam param_;
170168
}; // class RandomSampler

0 commit comments

Comments
 (0)