LCOV - code coverage report
Current view: top level - ml/tests - test_ConvLayers.cpp (source / functions) Hit Total Coverage
Test: test_coverage.info.cleaned Lines: 25 25 100.0 %
Date: 2022-02-28 03:37:41 Functions: 3 3 100.0 %

          Line data    Source code
       1             : #include "doctest/doctest.h"
       2             : #include "Input.h"
       3             : #include "Conv.h"
       4             : 
       5             : using namespace elsa;
       6             : using namespace doctest;
       7             : 
       8             : TEST_SUITE_BEGIN("ml");
       9             : 
      10             : // TODO(dfrank): remove and replace with proper doctest usage of test cases
      11             : #define SECTION(name) DOCTEST_SUBCASE(name)
      12             : 
      13           4 : TEST_CASE_TEMPLATE("ConvShapes", TestType, float)
      14             : {
      15           3 :     SECTION("Conv1D")
      16             :     {
      17             :         // ch
      18           2 :         IndexVector_t inputDims{{50}};
      19           2 :         VolumeDescriptor inputDesc(inputDims);
      20           3 :         auto input = ml::Input(inputDesc, 1);
      21             : 
      22           2 :         IndexVector_t filterDims{{3}};
      23           2 :         VolumeDescriptor filterDesc(filterDims);
      24             : 
      25           2 :         auto conv =
      26             :             ml::Conv1D<TestType>(5, filterDesc, ml::Activation::Relu, 2, ml::Padding::Valid, false);
      27             : 
      28           1 :         REQUIRE(conv.getNumberOfFilters() == 5);
      29           1 :         REQUIRE(conv.getFilterDescriptor() == filterDesc);
      30           1 :         REQUIRE(conv.getActivation() == ml::Activation::Relu);
      31           1 :         REQUIRE(conv.getStrides() == 2);
      32           1 :         REQUIRE(conv.useBias() == false);
      33             :     }
      34             : 
      35           3 :     SECTION("Conv2D")
      36             :     {
      37           2 :         IndexVector_t inputDims{{255, 255, 64}};
      38           2 :         VolumeDescriptor inputDesc(inputDims);
      39             : 
      40           3 :         auto input = ml::Input(inputDesc, 1);
      41             : 
      42           2 :         auto layer = ml::Conv2D<real_t>(3, std::array<index_t, 3>({7, 7, 64}), ml::Activation::Relu,
      43             :                                         3, ml::Padding::Same);
      44           1 :         layer.setInput(&input);
      45             : 
      46           1 :         layer.setInputDescriptor(inputDesc);
      47           1 :         layer.computeOutputDescriptor();
      48             : 
      49           2 :         IndexVector_t outDims{{255, 255, 3}};
      50           1 :         VolumeDescriptor outDesc(outDims);
      51             : 
      52           1 :         REQUIRE(layer.getOutputDescriptor().getNumberOfCoefficientsPerDimension() == outDims);
      53             :     }
      54           2 : }
      55             : TEST_SUITE_END();

Generated by: LCOV version 1.15