Skip to content

Commit 0888499

Browse files
authored
Add files via upload
1 parent ff86d33 commit 0888499

File tree

5 files changed

+142
-0
lines changed

5 files changed

+142
-0
lines changed

test/tTextDetection.m

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
classdef(SharedTestFixtures = {DownloadPretrainedCRAFTFixture}) tTextDetection < matlab.unittest.TestCase
2+
% Test for TextDetection
3+
4+
% Copyright 2021 The MathWorks, Inc.
5+
6+
% The shared test fixture downloads the model. Here we check the
7+
% inference on the pretrained model.
8+
properties
9+
RepoRoot = getRepoRoot;
10+
end
11+
12+
methods(Test)
13+
function exerciseDetection(test)
14+
model = load(fullfile(test.RepoRoot,'model','craftNet.mat'));
15+
inpImage = imread('businessCard.png');
16+
outputNames = {'Conv_118','Relu_109'};
17+
out = cell(size(outputNames'));
18+
19+
expectedBBoxes = [161.3333, 61.3333,542.6667, 61.3333,542.6667,145.3333,161.3333,145.3333;
20+
169.3333,312.0000,192.0000,312.0000,192.0000,340.0000,169.3333,340.0000;
21+
170.6667,272.0000,218.6667,272.0000,218.6667,304.0000,170.6667,304.0000;
22+
170.6667,348.0000,260.0000,348.0000,260.0000,384.0000,170.6667,384.0000;
23+
170.6667,386.6667,228.0000,386.6667,228.0000,418.6667,170.6667,418.6667;
24+
170.6667,424.0000,416.0000,424.0000,416.0000,454.6667,170.6667,454.6667;
25+
196.0000,310.6667,270.6667,310.6667,270.6667,349.3333,196.0000,349.3333;
26+
217.6480,269.3688,363.4014,272.5033,362.6325,308.2573,216.8791,305.1228;
27+
261.3333,349.3333,308.0000,349.3333,308.0000,380.0000,261.3333,380.0000;
28+
270.6667,310.6667,314.6667,310.6667,314.6667,342.6667,270.6667,342.6667;
29+
309.3333,349.3333,465.3333,349.3333,465.3333,381.3333,309.3333,381.3333;
30+
314.6667,312.0000,381.3333,312.0000,381.3333,344.0000,314.6667,344.0000;
31+
364.0000,276.0000,408.0000,276.0000,408.0000,304.0000,364.0000,304.0000];
32+
%Pre process
33+
[image, imageScale] = helper.preprocess(inpImage);
34+
35+
%Inferance
36+
[out{:}] = predict(model.craftNet,dlarray(image,'SSCB'),'Outputs',outputNames);
37+
38+
%Post process to get the boundingBoxes
39+
boundingBoxes = helper.postprocess(out,imageScale);
40+
41+
test.verifyEqual(boundingBoxes,expectedBBoxes,'AbsTol',double(1e-4));
42+
end
43+
end
44+
end

test/tdownloadPretrainedCRAFT.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
classdef(SharedTestFixtures = {DownloadPretrainedCRAFTFixture}) tdownloadPretrainedCRAFT < matlab.unittest.TestCase
2+
% Test for downloadPretrainedCRAFT
3+
4+
% Copyright 2021 The MathWorks, Inc.
5+
6+
% The shared test fixture DownloadPretrainedCRAFTFixture calls
7+
% tdownloadPretrainedCRAFT. Here we check that the downloaded files
8+
% exists in the appropriate location.
9+
10+
properties
11+
DataDir = fullfile(getRepoRoot(),'model');
12+
end
13+
14+
methods(Test)
15+
function verifyDownloadedFilesExist(test)
16+
dataFileName = 'craftNet.mat';
17+
test.verifyTrue(isequal(exist(fullfile(test.DataDir,dataFileName),'file'),2));
18+
end
19+
end
20+
end

test/tload.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
classdef(SharedTestFixtures = {DownloadPretrainedCRAFTFixture}) tload < matlab.unittest.TestCase
2+
% Test for loading the downloaded model.
3+
4+
% Copyright 2021 The MathWorks, Inc.
5+
6+
% The shared test fixture DownloadPretrainedCRAFTFixture calls
7+
% downloadPretrainedCRAFT. Here we check that the properties of
8+
% downloaded model.
9+
10+
properties
11+
DataDir = fullfile(getRepoRoot(),'model');
12+
end
13+
14+
methods(Test)
15+
function verifyModelAndFields(test)
16+
% Test point to verify the fields of the downloaded models are
17+
% as expected.
18+
19+
loadedModel = load(fullfile(test.DataDir,'craftNet.mat'));
20+
model = loadedModel.craftNet;
21+
test.verifyClass(model,'dlnetwork');
22+
test.verifyEqual(numel(model.Layers),63);
23+
test.verifyEqual(size(model.Connections),[66 2])
24+
test.verifyEqual(model.InputNames,{'Input_input'});
25+
test.verifyEqual(model.OutputNames,{'Conv_118'});
26+
end
27+
end
28+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
classdef DownloadPretrainedCRAFTFixture < matlab.unittest.fixtures.Fixture
2+
% DownloadPretrainedCRAFTFixture A fixture for calling
3+
% downloadDownloadPretrainedCRAFT if necessary. This is to
4+
% ensure that this function is only called once and only when tests
5+
% need it. It also provides a teardown to return the test environment
6+
% to the expected state before testing.
7+
8+
% Copyright 2021 The MathWorks, Inc
9+
10+
properties(Constant)
11+
CRAFTDataDir = fullfile(getRepoRoot(),'model')
12+
end
13+
14+
properties
15+
CRAFTExist (1,1) logical
16+
end
17+
18+
methods
19+
function setup(this)
20+
import matlab.unittest.fixtures.CurrentFolderFixture;
21+
this.applyFixture(CurrentFolderFixture ...
22+
(getRepoRoot()));
23+
24+
this.CRAFTExist = exist(fullfile(this.CRAFTDataDir,'craftNet.mat'),'file')==2;
25+
26+
% Call this in eval to capture and drop any standard output
27+
% that we don't want polluting the test logs.
28+
if ~this.CRAFTExist
29+
evalc('helper.downloadPretrainedCRAFT();');
30+
end
31+
end
32+
33+
function teardown(this)
34+
if this.CRAFTExist
35+
delete(fullfile(this.CRAFTDataDir,'craftNet.mat'));
36+
end
37+
end
38+
end
39+
end

test/tools/getRepoRoot.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function path = getRepoRoot()
2+
% getRepoRoot Return a path to the repository's root directory.
3+
4+
% Copyright 2020 The MathWorks, Inc.
5+
6+
thisFile = mfilename('fullpath');
7+
thisDir = fileparts(thisFile);
8+
9+
% the root is up two directories (<root>/test/tools/getRepoRoot.m)
10+
path = fullfile(thisDir,'..','..');
11+
end

0 commit comments

Comments
 (0)