This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f10ec2
commit e0a2f1f
Showing
4 changed files
with
107 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
from __future__ import print_function | ||
import os | ||
import sys | ||
import mxnet as mx | ||
import mxnet.ndarray as nd | ||
import numpy as np | ||
from mxnet import gluon | ||
from mxnet.base import MXNetError | ||
from mxnet.gluon.data.vision import transforms | ||
from mxnet.test_utils import assert_almost_equal, set_default_context | ||
from mxnet.test_utils import almost_equal | ||
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) | ||
sys.path.insert(0, os.path.join(curr_path, '../unittest')) | ||
from common import assertRaises, setup_module, with_seed, teardown | ||
|
||
|
||
set_default_context(mx.gpu(0)) | ||
|
||
@with_seed() | ||
def test_to_tensor(): | ||
# 3D Input | ||
data_in = np.random.uniform(0, 255, (300, 300, 3)).astype(dtype=np.uint8) | ||
out_nd = transforms.ToTensor()(nd.array(data_in, dtype='uint8')) | ||
assert_almost_equal(out_nd.asnumpy(), np.transpose( | ||
data_in.astype(dtype=np.float32) / 255.0, (2, 0, 1))) | ||
|
||
# 4D Input | ||
data_in = np.random.uniform(0, 255, (5, 300, 300, 3)).astype(dtype=np.uint8) | ||
out_nd = transforms.ToTensor()(nd.array(data_in, dtype='uint8')) | ||
assert_almost_equal(out_nd.asnumpy(), np.transpose( | ||
data_in.astype(dtype=np.float32) / 255.0, (0, 3, 1, 2))) | ||
|
||
# Invalid Input | ||
invalid_data_in = nd.random.uniform(0, 255, (5, 5, 300, 300, 3)).astype(dtype=np.uint8) | ||
transformer = transforms.ToTensor() | ||
assertRaises(MXNetError, transformer, invalid_data_in) |