def test_error_if_no_input(tmpdir): """Test that an exception is thrown when there is no input tensor""" model = EvalModelTemplate() model.example_input_array = None file_path = os.path.join(tmpdir, "model.onxx") with pytest.raises(ValueError, match=r'`input_sample` and `example_input_array` tensors are both missing'): model.to_onnx(file_path)
def test_error_if_no_input(tmpdir): """Test that an exception is thrown when there is no input tensor""" model = EvalModelTemplate() model.example_input_array = None file_path = os.path.join(tmpdir, "model.onnx") with pytest.raises(ValueError, match=r'Could not export to ONNX since neither `input_sample` nor' r' `model.example_input_array` attribute is set.'): model.to_onnx(file_path)
def test_tensorboard_log_graph(tmpdir, example_input_array): """ test that log graph works with both model.example_input_array and if array is passed externaly """ model = EvalModelTemplate() if example_input_array is not None: model.example_input_array = None logger = TensorBoardLogger(tmpdir, log_graph=True) logger.log_graph(model, example_input_array)
def test_error_if_input_sample_is_not_tensor(tmpdir): """Test that an exception is thrown when there is no input tensor""" model = EvalModelTemplate() model.example_input_array = None file_path = os.path.join(tmpdir, "model.onnx") input_sample = np.random.randn(1, 28 * 28) with pytest.raises(ValueError, match=f'Received `input_sample` of type {type(input_sample)}. Expected type is ' f'`Tensor`'): model.to_onnx(file_path, input_sample)
def test_tensorboard_log_graph_warning_no_example_input_array(tmpdir): """ test that log graph throws warning if model.example_input_array is None """ model = EvalModelTemplate() model.example_input_array = None logger = TensorBoardLogger(tmpdir, log_graph=True) with pytest.warns( UserWarning, match= 'Could not log computational graph since the `model.example_input_array`' ' attribute is not set or `input_array` was not given'): logger.log_graph(model)