def test_tensor_converter_3(): converter = TensorConverter() np_ = np.asarray([[1, 2, 3], [4, 5, 6]]) tensor_ = torch.from_numpy(np_) y, y_ = converter.output_proc(tensor_, None, training=True) assert y_ is None assert isinstance(y, torch.Tensor) assert y.shape == (2, 3) assert torch.equal(y, tensor_) y, y_ = converter.output_proc(tensor_, tensor_, training=True) assert isinstance(y, torch.Tensor) assert isinstance(y_, torch.Tensor) assert y.equal(y_) assert y.shape == (2, 3) assert torch.equal(y, tensor_) y, _ = converter.output_proc((tensor_, ), None, training=True) assert isinstance(y, tuple) assert isinstance(y[0], torch.Tensor) assert torch.equal(y[0], tensor_) y, y_ = converter.output_proc(tensor_, tensor_, training=False) assert isinstance(y, np.ndarray) assert isinstance(y_, np.ndarray) assert np.all(y == y_) assert y.shape == (2, 3) assert np.all(y == tensor_.numpy()) y, _ = converter.output_proc((tensor_, ), None, training=False) assert isinstance(y, tuple) assert isinstance(y[0], np.ndarray) assert np.all(y[0] == tensor_.numpy())
def test_tensor_converter_3(): np_ = np.asarray([[1, 2, 3], [4, 5, 6]]) tensor_ = torch.from_numpy(np_) converter = TensorConverter() y, y_ = converter.output_proc(tensor_, None, is_training=True) assert y_ is None assert isinstance(y, torch.Tensor) assert y.shape == (2, 3) assert torch.equal(y, tensor_) y, y_ = converter.output_proc(tensor_, tensor_, is_training=True) assert isinstance(y, torch.Tensor) assert isinstance(y_, torch.Tensor) assert y.equal(y_) assert y.shape == (2, 3) assert torch.equal(y, tensor_) y, _ = converter.output_proc((tensor_, ), None, is_training=True) assert isinstance(y, tuple) assert isinstance(y[0], torch.Tensor) assert torch.equal(y[0], tensor_) y, y_ = converter.output_proc(tensor_, tensor_, is_training=False) assert isinstance(y, np.ndarray) assert isinstance(y_, np.ndarray) assert np.all(y == y_) assert y.shape == (2, 3) assert np.all(y == tensor_.numpy()) y, _ = converter.output_proc((tensor_, ), None, is_training=False) assert isinstance(y, tuple) assert isinstance(y[0], np.ndarray) assert np.all(y[0] == tensor_.numpy()) converter = TensorConverter(argmax=True) y, y_ = converter.output_proc(tensor_, tensor_, is_training=False) assert isinstance(y, np.ndarray) assert isinstance(y_, np.ndarray) assert y.shape == (2, ) assert y_.shape == (2, 3) assert np.all(y == np.argmax(np_, 1)) y, y_ = converter.output_proc((tensor_, tensor_), None, is_training=False) assert isinstance(y, tuple) assert y_ is None assert y[0].shape == (2, ) assert y[0].shape == y[1].shape assert np.all(y[0] == np.argmax(np_, 1)) converter = TensorConverter(probability=True) y, y_ = converter.output_proc(tensor_, tensor_, is_training=False) assert isinstance(y, np.ndarray) assert isinstance(y_, np.ndarray) assert y.shape == (2, 3) assert y_.shape == (2, 3) assert np.all(y == softmax(np_, 1)) y, y_ = converter.output_proc((tensor_, tensor_), None, is_training=False) assert isinstance(y, tuple) assert y_ is None assert y[0].shape == (2, 3) assert y[0].shape == y[1].shape assert np.all(y[0] == softmax(np_, 1))