def test_check_tensor(self): # type: () -> None tensor = self._sample_float_tensor checker.check_tensor(tensor) tensor.raw_data = np.random.randn(2, 3).astype(np.float32).tobytes() self.assertRaises(checker.ValidationError, checker.check_tensor, tensor)
def test_check_string_tensor(self): tensor = TensorProto() tensor.data_type = TensorProto.STRING tensor.string_data.append('Test'.encode('utf-8')) checker.check_tensor(tensor) del tensor.string_data[:] tensor.raw_data = 'Test'.encode('utf-8') # string data should not be stored in raw_data field self.assertRaises(ValueError, checker.check_tensor, tensor)
def _create_onnx_tensor(self, nodes): onnx_tensors = [] register_names = [] for n in nodes: for tensor in n.onnx_tensors: checker.check_tensor(tensor) if not tensor.name in register_names: register_names.append(tensor.name) onnx_tensors.append(tensor) return onnx_tensors
def test_check_string_tensor(self): # type: () -> None tensor = TensorProto() tensor.data_type = TensorProto.STRING tensor.dims.append(1) tensor.string_data.append('Test'.encode('utf-8')) checker.check_tensor(tensor) del tensor.string_data[:] tensor.raw_data = 'Test'.encode('utf-8') # string data should not be stored in raw_data field self.assertRaises(checker.ValidationError, checker.check_tensor, tensor)
def test_check_tensor_zero_elem(self): # type: () -> None tensor = self._sample_0_elem_tensor checker.check_tensor(tensor)
def test_check_tensor(self): tensor = self._sample_float_tensor checker.check_tensor(tensor) tensor.raw_data = np.random.randn(2, 3).astype(np.float32).tobytes() self.assertRaises(ValueError, checker.check_tensor, tensor)