コード例 #1
0
    def test_device(self):
        device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
        summary(SingleInputNet(), (1, 28, 28), device=device)

        input_data = torch.randn(5, 1, 28, 28)
        summary(SingleInputNet(), input_data)
        summary(SingleInputNet(), input_data, device=device)

        summary(SingleInputNet(), input_data.to(device))
        summary(SingleInputNet(), input_data.to(device), device=torch.device("cpu"))
コード例 #2
0
    def test_single_input(self, capsys):
        model = SingleInputNet()
        input_shape = (1, 28, 28)

        summary(model, input_shape, depth=1)

        verify_output(capsys, "unit_test/test_output/single_input.out")
コード例 #3
0
    def test_single_input(capsys: CaptureFixture[str]) -> None:
        model = SingleInputNet()
        input_shape = (1, 28, 28)

        summary(model, input_shape, depth=1)

        verify_output(capsys, "unit_test/test_output/single_input.out")
コード例 #4
0
ファイル: output_test.py プロジェクト: HandsomeBBB/torchinfo
    def test_string_result() -> None:
        results = summary(SingleInputNet(),
                          input_size=(16, 1, 28, 28),
                          verbose=0)
        result_str = f"{results}\n"

        verify_output_str(result_str, "tests/test_output/single_input.out")
コード例 #5
0
ファイル: output_test.py プロジェクト: HandsomeBBB/torchinfo
    def test_single_input_all_cols(capsys: pytest.CaptureFixture[str]) -> None:
        model = SingleInputNet()
        col_names = (
            "kernel_size",
            "input_size",
            "output_size",
            "num_params",
            "mult_adds",
        )
        input_shape = (7, 1, 28, 28)
        summary(model,
                input_size=input_shape,
                depth=1,
                col_names=col_names,
                col_width=20)
        verify_output(capsys, "tests/test_output/single_input_all.out")

        summary(
            model,
            input_data=torch.randn(*input_shape),
            depth=1,
            col_names=col_names,
            col_width=20,
        )
        verify_output(capsys, "tests/test_output/single_input_all.out")
コード例 #6
0
    def test_single_input(self):
        model = SingleInputNet()
        input_shape = (1, 28, 28)

        results = summary(model, input_shape)

        assert results.total_params == 21840
        assert results.trainable_params == 21840
コード例 #7
0
    def test_string_result(self):
        results = summary(SingleInputNet(), (1, 28, 28), verbose=0)

        result_str = str(results) + "\n"

        with open("unit_test/test_output/single_input.out", encoding="utf-8") as output_file:
            expected = output_file.read()
        assert result_str == expected
コード例 #8
0
ファイル: output_test.py プロジェクト: HandsomeBBB/torchinfo
    def test_row_settings(capsys: pytest.CaptureFixture[str]) -> None:
        model = SingleInputNet()

        summary(model,
                input_size=(16, 1, 28, 28),
                row_settings=("var_names", ))

        verify_output(capsys, "tests/test_output/row_settings.out")
コード例 #9
0
    def test_single_input(self):
        model = SingleInputNet()
        input_shape = (1, 28, 28)

        results = summary(model, input_shape)

        assert len(results.summary_list) == 5, "Should find 6 layers"
        assert results.total_params == 21840
        assert results.trainable_params == 21840
コード例 #10
0
    def test_batch_size_optimization() -> None:
        model = SingleInputNet()

        # batch size intentionally omitted.
        results = summary(model, (1, 28, 28), batch_dim=0)

        assert len(results.summary_list) == 5, "Should find 6 layers"
        assert results.total_params == 21840
        assert results.trainable_params == 21840
コード例 #11
0
    def test_single_input() -> None:
        model = SingleInputNet()

        # input_size keyword arg intentionally omitted.
        results = summary(model, (2, 1, 28, 28))

        assert len(results.summary_list) == 5, "Should find 6 layers"
        assert results.total_params == 21840
        assert results.trainable_params == 21840
コード例 #12
0
    def test_string_result() -> None:
        results = summary(SingleInputNet(),
                          input_size=(16, 1, 28, 28),
                          verbose=0)
        result_str = str(results) + "\n"

        with open("tests/test_output/single_input.out",
                  encoding="utf-8") as output_file:
            expected = output_file.read()
        assert result_str == expected
コード例 #13
0
    def test_single_input_batch_dim(capsys: CaptureFixture[str]) -> None:
        model = SingleInputNet()
        input_shape = (7, 1, 28, 28)
        summary(model, input_shape, depth=1, batch_dim=None)
        verify_output(capsys,
                      "unit_test/test_output/single_input_batch_dim.out")

        input_data = torch.randn(*input_shape)
        summary(model, input_data, depth=1, batch_dim=None)
        verify_output(capsys,
                      "unit_test/test_output/single_input_batch_dim.out")
コード例 #14
0
    def test_device() -> None:
        device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
        model = SingleInputNet()
        # input_size
        summary(model, input_size=(5, 1, 28, 28), device=device)

        # input_data
        input_data = torch.randn(5, 1, 28, 28)
        summary(model, input_data=input_data)
        summary(model, input_data=input_data, device=device)
        summary(model, input_data=input_data.to(device))
        summary(model, input_data=input_data.to(device), device=torch.device("cpu"))
コード例 #15
0
ファイル: output_test.py プロジェクト: dsp6414/torch-summary
    def test_single_input_with_kernel_macs(capsys):
        model = SingleInputNet()
        input_shape = (1, 28, 28)

        summary(
            model,
            input_shape,
            depth=1,
            col_names=("kernel_size", "output_size", "num_params", "mult_adds"),
            col_width=20,
        )

        verify_output(capsys, "unit_test/test_output/single_input_all.out")
コード例 #16
0
ファイル: output_test.py プロジェクト: HandsomeBBB/torchinfo
 def test_single_input_batch_dim(
         capsys: pytest.CaptureFixture[str]) -> None:
     model = SingleInputNet()
     col_names = (
         "kernel_size",
         "input_size",
         "output_size",
         "num_params",
         "mult_adds",
     )
     summary(
         model,
         input_size=(1, 28, 28),
         depth=1,
         col_names=col_names,
         col_width=20,
         batch_dim=0,
     )
     verify_output(capsys, "tests/test_output/single_input_batch_dim.out")
コード例 #17
0
ファイル: output_test.py プロジェクト: LeiWang1999/torchinfo
    def test_basic_summary(capsys: pytest.CaptureFixture[str]) -> None:
        model = SingleInputNet()

        summary(model)

        verify_output(capsys, "unit_test/test_output/basic_summary.out")
コード例 #18
0
ファイル: output_test.py プロジェクト: HandsomeBBB/torchinfo
    def test_single_input(capsys: pytest.CaptureFixture[str]) -> None:
        model = SingleInputNet()

        summary(model, input_size=(16, 1, 28, 28), depth=1)

        verify_output(capsys, "tests/test_output/single_input.out")
コード例 #19
0
    def test_input_tensor(self):
        input_data = torch.randn(5, 1, 28, 28)

        metrics = summary(SingleInputNet(), input_data)

        assert metrics.input_size == [torch.Size([5, 1, 28, 28])]
コード例 #20
0
    def test_basic_summary(self, capsys):
        model = SingleInputNet()

        summary(model)

        verify_output(capsys, "unit_test/test_output/basic_summary.out")