Skip to content

Commit 4df9e3b

Browse files
committed
fix: generators unit tests
1 parent cef820b commit 4df9e3b

File tree

10 files changed

+33
-24
lines changed

10 files changed

+33
-24
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ node_js:
44
install:
55
- npm install -g codecov nyc doxdox
66
- npm install
7+
- mkdir tmp
8+
79
cache:
810
directories:
911
- node_modules/opencv-build

lib/augmenters/additive-gaussian-noise.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const AdditiveAugmenter = require('./additive');
44

55
/**
66
* Adds noise sampled from a gaussian distribution
7-
*
7+
*
88
* Warning : This function is slow, use `ia.additiveNoise` with tensorflowjs for fast noise generation
99
*
1010
* @param {Object | Number | Hasard} sigma options, if number, this is sigma

lib/augmenters/draw-boxes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const AbstractAugmenter = require('./abstract');
33

44
/**
55
* Draw boxes in the image
6-
*
6+
*
77
* @param {Object} opts options, if array, or number, considered as the color
88
* @param {ArrayColor} [opts.color] the RGB color to draw
99
* @example

lib/generators/truncated-normal-noise.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const GaussianNoiseGenerator = require('./gaussian-noise');
44
const getMatrixesPerChannelFixed = ({perChannel, nImages, width, height, channels, isHasardScale, means, stds, scales, backend}) => {
55
return backend.backendLib.tidy(() => {
66
if (nImages === 0) {
7-
return backend.zeros([nImages, height, width, channels]);
7+
return backend.backendLib.zeros([nImages, height, width, channels]);
88
}
99

1010
const shape = isHasardScale ?
@@ -145,8 +145,10 @@ class TruncatedNormalNoiseGenerator extends GaussianNoiseGenerator {
145145
width: o.width,
146146
height: o.height,
147147
channels: o.channels
148-
}).unstack();
148+
});
149+
149150
const notPerChannelsMatrixesUnstacked = notPerChannelsMatrixes.unstack();
151+
150152
this.backend.dispose(notPerChannelsMatrixes);
151153

152154
const tensorsReordered = imageProps.map(im => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
},
7171
"dependencies": {
7272
"debug": "^4.1.1",
73-
"hasard": "^1.3.1",
73+
"hasard": "^1.4.0",
7474
"jimp": "^0.6.0"
7575
}
7676
}

test/benchmark/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const formatBenchmark = require('./format-benchmark');
2323

2424
const gridSide = 5;
2525

26-
const batchSize = gridSide*gridSide;
26+
const batchSize = gridSide * gridSide;
2727

2828
const filenames = new Array(batchSize).fill(path.join(__dirname, '../data', 'opencv4nodejs', 'lenna.png'));
2929

test/generators/gaussian-noise.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ const test = require('ava');
33
const GaussianNoise = require('../../lib/generators/gaussian-noise');
44
const macroGenerator = require('../macros/generator');
55

6-
const width = 59;
7-
const height = 47;
6+
const wdth = 59;
7+
const hght = 47;
88
const channels = 3;
99
const mean = 128;
1010
const sigma = 50;
1111

1212
test('gaussian-noise', macroGenerator, GaussianNoise, {
13-
debugOutput: path.join(__dirname, '../..', 'tmp/gaussian-noise.png'),
14-
expectImg: (t, img) => {
15-
t.is(img.cols, width);
16-
t.is(img.rows, height);
17-
const sum = img.getDataAsArray()
13+
debugOutput: [path.join(__dirname, '../..', 'tmp/gaussian-noise.png')],
14+
expectImg: (t, {images}, backend) => {
15+
const metadatas = backend.getMetadata(images);
16+
const [{width, height}] = metadatas;
17+
t.is(width, wdth);
18+
t.is(height, hght);
19+
const sum = backend.imageToArray(images)
20+
.reduce((a, b) => a.concat(b))
1821
.reduce((a, b) => a.concat(b))
1922
.reduce((a, b) => a.concat(b))
2023
.reduce((a, b) => a + b);
@@ -23,8 +26,8 @@ test('gaussian-noise', macroGenerator, GaussianNoise, {
2326
Math.abs((sum / (width * height * channels)) - mean) < 100 / Math.sqrt(width * height * channels)
2427
);
2528
},
26-
width,
27-
height,
29+
width: wdth,
30+
height: hght,
2831
channels,
2932
options: {
3033
mean,

test/generators/truncated-normal-noise.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ test('truncated-normal noise', macroGenerator, TruncatedNormalNoise, {
1717
// path.join(__dirname, '../..', 'tmp/truncated-normal-noise3.png')
1818
// ],
1919
expectImg: (t, {images}, backend) => {
20-
const {width, height, nImages} = backend.getMetadata(images);
20+
const metadatas = backend.getMetadata(images);
21+
const [{width, height}] = metadatas;
2122
t.is(width, wdth);
2223
t.is(height, hght);
23-
t.is(nImages, imageNumber);
24+
t.is(metadatas.length, imageNumber);
2425
const flatten = a => {
2526
return a.reduce((flat, i) => {
2627
if (Array.isArray(i)) {
@@ -34,9 +35,9 @@ test('truncated-normal noise', macroGenerator, TruncatedNormalNoise, {
3435
const flat = flatten(backend.imageToArray(images));
3536

3637
const sum = flat.reduce((a, b) => a + b, 0);
37-
const l2 = (width * height * channels * nImages);
38+
const l2 = (width * height * channels * imageNumber);
3839
const average = (sum / l2);
39-
const tolerance = 1000 / Math.sqrt(width * height * channels * nImages);
40+
const tolerance = 1000 / Math.sqrt(width * height * channels * imageNumber);
4041
t.true(
4142
Math.abs(average - mean) < tolerance
4243
);
@@ -66,10 +67,11 @@ test('truncated-normal noise with hasard', macroGenerator, TruncatedNormalNoise,
6667
// path.join(__dirname, '../..', 'tmp/truncated-normal-noise9.png')
6768
// ],
6869
expectImg: (t, {images}, backend) => {
69-
const {width, height, nImages} = backend.getMetadata(images);
70+
const metadatas = backend.getMetadata(images);
71+
const [{width, height}] = metadatas;
7072
t.is(width, wdth);
7173
t.is(height, hght);
72-
t.is(nImages, imageNumber);
74+
t.is(metadatas.length, imageNumber);
7375
},
7476
width: wdth,
7577
height: hght,

test/macros/augmenter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ module.exports = function (t, Cstr, {
1515
backendLibs = [
1616
require('opencv4nodejs'),
1717
require('@tensorflow/tfjs-node')
18-
//,
19-
//require('@tensorflow/tfjs-node-gpu')
18+
// ,
19+
// require('@tensorflow/tfjs-node-gpu')
2020
]
2121
}) {
2222
return PromiseBlue.map(backendLibs, backendLib => {

test/macros/generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = function (t, Cstr, {
1111
channels,
1212
options,
1313
backendLibs = [
14-
require('@tensorflow/tfjs-node-gpu'),
14+
require('@tensorflow/tfjs-node'),
1515
require('opencv4nodejs')
1616
]
1717
}) {

0 commit comments

Comments
 (0)