From 16041a6117c6e4b360fe88258c4fc8f55f53669b Mon Sep 17 00:00:00 2001 From: Tzu-Wei Huang Date: Sat, 8 Jun 2019 13:13:18 +0800 Subject: [PATCH] Make tests deterministic (#443) * replace np.random with predictable function. * update expect files * update .travis.yml to solve protobuf issue --- .travis.yml | 1 + .../expect/test_pr_curve.test_pr_purve.expect | 6 +-- .../test_pr_curve.test_pr_purve_raw.expect | 12 ++--- tests/expect/test_summary.test_audio.expect | 4 +- .../test_summary.test_histogram_auto.expect | 37 ++++++++-------- .../test_summary.test_histogram_doane.expect | 37 ++++++++-------- .../test_summary.test_histogram_fd.expect | 37 ++++++++-------- ...y.test_image_with_3_channel_batched.expect | 2 +- .../test_summary.test_image_with_boxes.expect | 2 +- ...summary.test_image_with_one_channel.expect | 2 +- ...test_image_with_one_channel_batched.expect | 2 +- ..._summary.test_image_without_channel.expect | 2 +- tests/expect/test_summary.test_video.expect | 2 +- tests/expect_reader.py | 6 --- tests/test_pr_curve.py | 31 +++++++++++-- tests/test_summary.py | 44 ++++++++----------- 16 files changed, 118 insertions(+), 109 deletions(-) diff --git a/.travis.yml b/.travis.yml index cf145de4..29e18da2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,7 @@ install: - bash miniconda.sh -b -p $HOME/miniconda - export PATH="$HOME/miniconda/bin:$PATH" - export BOTO_CONFIG=/dev/null # https://github.com/travis-ci/travis-ci/issues/7940 + - export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python - hash -r - conda config --set always_yes yes --set changeps1 no - conda update -q conda diff --git a/tests/expect/test_pr_curve.test_pr_purve.expect b/tests/expect/test_pr_curve.test_pr_purve.expect index 7ec5050b..44b54c9f 100644 --- a/tests/expect/test_pr_curve.test_pr_purve.expect +++ b/tests/expect/test_pr_curve.test_pr_purve.expect @@ -10,11 +10,11 @@ value { size: 1 } } - float_val: 56.0 - float_val: 44.0 + float_val: 57.0 + float_val: 43.0 float_val: 0.0 float_val: 0.0 - float_val: 0.5600000023841858 + float_val: 0.57 float_val: 1.0 } metadata { diff --git a/tests/expect/test_pr_curve.test_pr_purve_raw.expect b/tests/expect/test_pr_curve.test_pr_purve_raw.expect index 135dc196..0d09fb09 100644 --- a/tests/expect/test_pr_curve.test_pr_purve_raw.expect +++ b/tests/expect/test_pr_curve.test_pr_purve_raw.expect @@ -30,15 +30,15 @@ value { float_val: 54.0 float_val: 70.0 float_val: 75.0 - float_val: 0.3333333134651184 - float_val: 0.3786981999874115 - float_val: 0.5384616255760193 + float_val: 0.3333333 + float_val: 0.3786982 + float_val: 0.5384616 float_val: 1.0 float_val: 0.0 float_val: 1.0 - float_val: 0.8533334136009216 - float_val: 0.2800000011920929 - float_val: 0.06666669994592667 + float_val: 0.8533334 + float_val: 0.28 + float_val: 0.0666667 float_val: 0.0 } metadata { diff --git a/tests/expect/test_summary.test_audio.expect b/tests/expect/test_summary.test_audio.expect index 120c33eb..60cb2fb8 100644 --- a/tests/expect/test_summary.test_audio.expect +++ b/tests/expect/test_summary.test_audio.expect @@ -1,10 +1,10 @@ value { tag: "dummy" audio { - sample_rate: 44100.0 + sample_rate: 44100 num_channels: 1 length_frames: 42 - encoded_audio_string: "RIFFx\000\000\000WAVEfmt \020\000\000\000\001\000\001\000D\254\000\000\210X\001\000\002\000\020\000dataT\000\000\000>F\212[&M\276E96\254R\0028$rX{\0241Ve\262C\265Hyv\027\t&\013\226\002\222j\231c[oB}Jf\021;\347c#\017\350QY\022\351x\313B\0235\334!\031cb:\301Hg\002\016OXN\367N\313xEW\003.\3607" + encoded_audio_string: "RIFFx\000\000\000WAVEfmt \020\000\000\000\001\000\001\000D\254\000\000\210X\001\000\002\000\020\000dataT\000\000\000\000\000\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177\377\177" content_type: "audio/wav" } } diff --git a/tests/expect/test_summary.test_histogram_auto.expect b/tests/expect/test_summary.test_histogram_auto.expect index 84608817..81e479e4 100644 --- a/tests/expect/test_summary.test_histogram_auto.expect +++ b/tests/expect/test_summary.test_histogram_auto.expect @@ -1,24 +1,23 @@ value { tag: "dummy" histo { - min: 0.0005459648969956543 - max: 0.9998085781169653 - num: 1024.0 - sum: 506.74752192429736 - sum_squares: 337.2470761005681 - bucket_limit: 0.0005459648969956543 - bucket_limit: 0.1822300763915356 - bucket_limit: 0.36391418788607555 - bucket_limit: 0.5455982993806154 - bucket_limit: 0.7272824108751554 - bucket_limit: 0.9089665223696954 - bucket_limit: 0.9998085781169653 - bucket: 0.0 - bucket: 190.0 - bucket: 192.0 - bucket: 195.0 - bucket: 178.0 - bucket: 169.0 - bucket: 100.0 + max: 1023.0 + num: 1024 + sum: 523776.0 + sum_squares: 357389824.0 + bucket_limit: 0.0 + bucket_limit: 186.0 + bucket_limit: 372.0 + bucket_limit: 558.0 + bucket_limit: 744.0 + bucket_limit: 930.0 + bucket_limit: 1023.0 + bucket: 0 + bucket: 186 + bucket: 186 + bucket: 186 + bucket: 186 + bucket: 186 + bucket: 94 } } diff --git a/tests/expect/test_summary.test_histogram_doane.expect b/tests/expect/test_summary.test_histogram_doane.expect index 56c82f19..81e479e4 100644 --- a/tests/expect/test_summary.test_histogram_doane.expect +++ b/tests/expect/test_summary.test_histogram_doane.expect @@ -1,24 +1,23 @@ value { tag: "dummy" histo { - min: 0.0005459648969956543 - max: 0.9998085781169653 - num: 1024.0 - sum: 506.74752192429736 - sum_squares: 337.2470761005681 - bucket_limit: 0.0005459648969956543 - bucket_limit: 0.1670897337669906 - bucket_limit: 0.33363350263698555 - bucket_limit: 0.5001772715069805 - bucket_limit: 0.6667210403769754 - bucket_limit: 0.8332648092469703 - bucket_limit: 0.9998085781169653 - bucket: 0.0 - bucket: 177.0 - bucket: 171.0 - bucket: 182.0 - bucket: 158.0 - bucket: 157.0 - bucket: 179.0 + max: 1023.0 + num: 1024 + sum: 523776.0 + sum_squares: 357389824.0 + bucket_limit: 0.0 + bucket_limit: 186.0 + bucket_limit: 372.0 + bucket_limit: 558.0 + bucket_limit: 744.0 + bucket_limit: 930.0 + bucket_limit: 1023.0 + bucket: 0 + bucket: 186 + bucket: 186 + bucket: 186 + bucket: 186 + bucket: 186 + bucket: 94 } } diff --git a/tests/expect/test_summary.test_histogram_fd.expect b/tests/expect/test_summary.test_histogram_fd.expect index 84608817..81e479e4 100644 --- a/tests/expect/test_summary.test_histogram_fd.expect +++ b/tests/expect/test_summary.test_histogram_fd.expect @@ -1,24 +1,23 @@ value { tag: "dummy" histo { - min: 0.0005459648969956543 - max: 0.9998085781169653 - num: 1024.0 - sum: 506.74752192429736 - sum_squares: 337.2470761005681 - bucket_limit: 0.0005459648969956543 - bucket_limit: 0.1822300763915356 - bucket_limit: 0.36391418788607555 - bucket_limit: 0.5455982993806154 - bucket_limit: 0.7272824108751554 - bucket_limit: 0.9089665223696954 - bucket_limit: 0.9998085781169653 - bucket: 0.0 - bucket: 190.0 - bucket: 192.0 - bucket: 195.0 - bucket: 178.0 - bucket: 169.0 - bucket: 100.0 + max: 1023.0 + num: 1024 + sum: 523776.0 + sum_squares: 357389824.0 + bucket_limit: 0.0 + bucket_limit: 186.0 + bucket_limit: 372.0 + bucket_limit: 558.0 + bucket_limit: 744.0 + bucket_limit: 930.0 + bucket_limit: 1023.0 + bucket: 0 + bucket: 186 + bucket: 186 + bucket: 186 + bucket: 186 + bucket: 186 + bucket: 94 } } diff --git a/tests/expect/test_summary.test_image_with_3_channel_batched.expect b/tests/expect/test_summary.test_image_with_3_channel_batched.expect index e8f9bcec..2895ff76 100644 --- a/tests/expect/test_summary.test_image_with_3_channel_batched.expect +++ b/tests/expect/test_summary.test_image_with_3_channel_batched.expect @@ -4,6 +4,6 @@ value { height: 8 width: 16 colorspace: 3 - encoded_image_string: "\211PNG\r\n\032\n\000\000\000\rIHDR\000\000\000\020\000\000\000\010\010\002\000\000\000\177\024\350\300\000\000\001\223IDATx\234\001\210\001w\376\001\2132\250+,\241\343sT\361G\320\342\275\2658C*\313\340Et\177\005L\025\256\301\t\335\314`\355\301U>\274\363\366\007\3342\316\353:`\351\003\002j\307\352\253<]0\353\t\374\361\001$s\302H\006\021\243S\3363\247M \036\004\3013?\244R \260K}\315\323\314\321b=\237\365\030\005\362\025\000\005Q\315\324i\263\306\020\031\335\260\352\371\220\266\313C\376u\205&\307\027\335\210VB\344\365_\374;\2257\362E\251\360^C\3132\005\240u\301\336\013\002\031A\\\317\203\351^A\006\023\372\356\214\221\027\236s\223\316\304A\376\0274\311\364\211}\343\264\232b\357\234\021\t\367h5\233Z\302@Z/\n\233\376\002V\003\210\355\031\327\340\202\231\255W\004\027\213+4\216I\255r\233\350\307J\3364\242\221\313o\031\300\004c\037_Qy\263\334\013,\373\210\300k\300\352\001[?\272\024SqB\004Y^\373\211\233\247%\001\272\322\212\200\306\353eodA\366\202\303\267.\035\2448\375\352\363\362l\027\336\224\320\217DO\300\255\002\365s\236\355\271\301\3409/`\324\373R\250\367o\242\232\000n\311\t\331\003XO\267\027`\311O)(\265\030\337W\322\340\356=.Jp\205\231\021\303\002V\006\226\3444\260\345$\325\317?\216,\214\221\002\006\261r$\322\372\234\371H\255\345_\333E\327\212\302\3161C\r\262\032Z\214\322V\027\265\347\224jn\340\302\315!*\322\020\000\000\000\000IEND\256B`\202" + encoded_image_string: "\211PNG\r\n\032\n\000\000\000\rIHDR\000\000\000\020\000\000\000\010\010\002\000\000\000\177\024\350\300\000\000\000+IDATx\234cd8\320\360\037\033pww\307*\316\362\343\307\217\037\330$~\374\370\361\037\233\004\013\016\365\377q\211\217H\r\000d\305y\224,\220Z\033\000\000\000\000IEND\256B`\202" } } diff --git a/tests/expect/test_summary.test_image_with_boxes.expect b/tests/expect/test_summary.test_image_with_boxes.expect index a1dd1e69..4364b484 100644 --- a/tests/expect/test_summary.test_image_with_boxes.expect +++ b/tests/expect/test_summary.test_image_with_boxes.expect @@ -4,6 +4,6 @@ value { height: 32 width: 32 colorspace: 3 - encoded_image_string: "\211PNG\r\n\032\n\000\000\000\rIHDR\000\000\000 \000\000\000 \010\002\000\000\000\374\030\355\243\000\000\013\243IDATx\234\245\324\367?\325\217\027\007\360\367\275\366\316\276\327\272\250\214\233}\315\310\236\327.[7\371d\217\224\225Y\312*;|\262IH$\231W)\233\214p\021\327\274\266\310\0257\343\272\\W\337\037|\377\203\317\371\003\316\363\361z\235\307\343\000\343\033\273\233\317\3730\010g\211\367\233\257\313M\335a^l\272\020?\266J\035%\272\031\221Hz\371\332\303\332q\'f1\'h\'\265h\213\254U\232\207\331\277;:\274\320\216\274?\347\256\270\347\270 \202\345-\367,u~\277B\257%zSm\252h.\377\312v\366\020o\355\335W\252+\264\332\215\373\324V9\177V+\346\370\364\253b\350i\034\212jo\223\233\250*\272\332FF\303\267\366*d2\017\231\034\270\336\346\266L\302\23618\252\3356\367EJ\274\332\th\243J\362\221\373\025i\351-\362!\035\273\243\351\313\006on\266\3568\214\372\276\345\010\251\200\0107\233\313\205wA\266\262\037\311\224K\225$Pc\017\'\367z\241\356~R.}\306z\352\313\013\363\351\323\243\271&\260e\026\'\312K\215\326\033\035\"c\333\365\356-g\374\246\225<\272\247<\n\204\363,\3043\262\271\321C\310\212S\266\267\253\332\307\244\271\341\204\344D\026\240\036N\307\210\317\241\336mn\222\303\034|+\320\207S\350\024\rB\347\322\000\216\337\251\310j\026\261\357r>)\371\"\247\357\362_e\2732\341\326\025(D\317\356\344\274P\303\336\311\034o\241\365\346Z\317\301\270\024+i\203\023Rp\205\235\307r\241V\352rL\333S\313^A\227\315\261x1\247\216\264S[\377\025<~v\236\317\211\371\264K{\211\374\220#\201/:\314\001ME]\215\271\372\347\306\310\237uw\336\036\364\320\201l\033\"\313\026\362\354\354\257m6\347t{\343\325.\335\222\000\2519\2412\022*&\204\034\335\376\226F\340\032\302\337\372Ej\177K\027\004}\327R\r_\205\244`{Q\271\214\304\320\217\225\337z\365O\t\244\215\0279l\364\025\356\372`\211\354\006J\333S\260Z\211\207}\"=\347\3671>oQ\213\361\301\363Rn\301\325z\325Y\323\237\375k\032\017\256W\365\331\377#;\242\352\'\316\000N\346\335\236:&\367\'\262\000_\244\314\016C\362\022\025XW\367D\313\007\022m\'\204Gqq\332_\323\rb\337i\261\245@\324\371\244\266\212\332]\020\2163kh\274\031\030\221\036\277xJ\327\331\322\tQey[cqk)\253\362\315%2\273\203\216\333\353/<\343N\254\213\244\267\224\251\242\300\'I\021BK\rT\233\252\254t2na\217o\345M\ns\345. hSUN\260}\r\254\230\031G\347\nT\335h\317\032/\035^\371\276\033+\017\273\247\235;\210\320\352E\355,\334\020I\314\3455h\t\210\027\307H\317]\333$\021\251s\364\353\3236\356Ux_\037\020\343W\312c(rv\365\036\223\\\306OC8\021\315\346\255\325\333TF\032\254@\323I\300\tH\344\203\014f\373*#n\330M\327f\217\327\244\016\022o\263\256\010\222l\230=\337X\211D*I\244\335\001\315\244\266\363\340\n\231\317\270|M\257\220=6\3728M^|\3249\301\373+\306n\335\200\032x\244\300y\326-\252\206\271w\013\237\326\375\340D\3743\353\243\351^!\021oO[\026/\233\032\244\274}\037B\321\233;\222(t\0239\226\377\333\271o\370\210\273\006\316\353\322\345\270\243J\323\303\\\302\360\\\007T\310\037\021\022r\3229\3578eQ\303)e\202Y\362\316\346B\231\312\231\002F\316\333\212&\265\321I\300\177\033\352Bv2\37569\260Nxd\263\032\340+\031\312\007JQ.\342\227RTdN>Z\212\000\321\377q?\000\030\032\224\306\257\306\n\302/KTU0q\317\035\223x\201\206Nil]a\306\002W8\337_\000\370\013\000\304G4O\273\276\230I\317\245\\\013\372}\377~\234\265\221>\007hiZ\366N\357\t\220\204\323:\321\263\3468\232\353A\005\353\231>D\211\331\252l,\017\222\tWn\235a\033\357\276\263\005\210l|\203\243n5\257S4\177\302T\332\307\340\351\217\361S\352H\303\234\240\344\241h\344\255\013\3402\365\221\337\255^l\214\323\030\0355_Z\245\370\242\202y#\214\263\370\267\337\3019\377\241~\306\204\231f><7*X\220j\201\224\337\360\373l\372\336\330\365\033v\255Zb\333\221\375F\000c[]\031\321\303k\ty7\365x\024\352\320\024\311\177`y\317\361Y\340\272YG\357\374\376\005`\222\033\276\350\337\"\260i\241,\313.S\217\3628\256o\2272L@\314G\325\r\002\337\344\375\242m.\025L()k\376\016\267Q\026\260\237\263\036\0366f\220x\310\221\377;KP\306\035\370\354Q\372\246P\017\363g3B\244\373\3276;3W?2\342\030\035D\360Q\372\"\345\000\273\000\302\016\216\227\343\320\255\270\002\257\202z\027\307\200Xy\227U\357\335\257\3616 &\306\372\253\036\333y\203\315j\025\322SG\221\267\370/\363m9s\337\331\335\r\303\013\371\033_\026\264\233\327\002\345i\267\335\3666\226\023\027\024\030Z/r\232,\351\354\361\362JC\006\3469H*\014s\223j\0249\000\000\010\230x\365{\347}Z\257\305\370~\367_\0106C\034\211TeA4<\2466`M\035\323\365wI=\276\217\361\036\202\177\372\213\315\346\2002\023\277\022\365Z\204\370\363Y_u\257\340\262\000\034\353\310\353\314C\017Y\007\0370rt\207\313\341y\225\022\357!\033Vt\3514r;\020z\221@\312\025\'\270b\267qu\211uB\360\224J\003\022\274\261P\3764\203\255\000U\310`O\020\356\222`\265j\375YY \032+;\023\tr\334\000\017\247&\242&\010\372\237\313y\031\320F@_t\230J\366\330O\341 \306\245c\233\356$\3509m\270\251\367\270\332G3\230\272\330Q\303\377\217\234\322\247\346\235\306.\306\335(\031\356vdbi\276\334B0\266\345$|\016I\306\210\334T\001aH\251\365\222\202\336\310O\257\245\033\2769H\315F\020\306\342[\340\263\246?V\233XA\252\255\010\217\"\337\307\364O\034\317\242p\272\315\347\306\260kFkZ\215]\366\022\3671\245\2410\007&\000\000\010-\007\231=\017\242\341\026\212\363\004;K\353\356\367\307T\314\032&\255\004[\347\317\253\215\020\274a\0166\027\201\242\270f\352\212\273\202w\2113A\377\340\362\322\266pZ\024MK-\027j\360\227\273k\377\240K:[P\376\201\276\242g~b\"\246pf\371&\221\204\211w\2421 \n\000\000\000 \30070\36539\201wz*\022]OKl\275*^Z\252\037o\274\337xlsm7\357\245\207\303\275\211\310\227\212\350\356G\223P\007)xp)m\\\312\034\246\372uG\255E\276\026\360\2557h\206[;\232\264&\313\354J\331e\020\326v\r\353\362c\007\346\t\332\337\211\035\n\027\025i\273\331\353\271p\ng\260&T\177\270\202\305[=\216.\2717\375\371\312\020\355H\225\177\363\311[\257\341\3318\303\360\252\301cx\235\036\255;\225\025gd\216\262N\324\367\211:-\365\361s\3002\252nP4\034=\3632-\263\240\361\353\261O\243$\210h\0006mz\326x\203\033\265x\001\314\3333\213\375\311\001\220\023\004M\003\303\354_\262:]ual\374\223\231z\3273H~\210\262\002\333\270\344`w\022s\337\007\261\313_%\211\304\273\363\336\355EN?\030\231$\033d:\200-\215\367\3612kN\235\307B\317a\235\325\\+\343\337\241\327%\273n\311S7-\023\335\366.\000\323\315\371\035\257|=\233\214\037g\231\344r\263~TQ\034\237\346\245\001\351\260&\357\000|#B\245\330O\220\350\374\251\\\022q\345\201\224\244\2365o\374\230\034\375\213\334M\246\251\261\3205py\340\027\033\347\367\005\343\323\347\365r\3132\261\202\355\256\253\221V3\225d\201\317\377\026G\205^\374\253w\037\215\2746k\\\360\037\202\221\222\304\017>\373\267Ic\217f?\203\356\225\301\336\037\341\255i\024\276\350Z\030u(\036h\204\014`\267\3224\325j&\223\272k\002\031`\244\366q14\270\2261\324\267sr\332\363l\372\215}\035;z2d\032\266\360\225\336:\241\304W(\253k\345\002\020?8\257\273)q\330$-a\211\231\253\300(h\014\220\270\336\347\177zz\267\354H\236\305\263\2738\231\252\201\301D&{\021\nT\353\006\225B\n\357h\365\253x\226\226\305U\016\321\017\003\n{\003\250\314\255\246B\272\nv\370\316\376!.!gl8e\213\031c\350\313xG\207\352\242\242\352\222v\223\007\342\324\340pw\342\236\305\321.A\005\274\312\3301\237\010z\273\177j\277\345\223\374/\tc\216\202\332 \207\327\255\030\243[\307D\024F\264\026X\014_\225\300\216cB\311\340\223S\317\001\010\023{(5\236\200c\2659\023\304\336\221>\315S\336.\255:\016Z\276?s\221\340\005U\233Q\331\343kV\272\315\373#\030M\016\337\327\274\260\312\242\227XV\252lO\2667\'I\"\373\332\312\010\351\021\037\227\225\314\235m\264\335\344(\300\340\367\234\242\266\257\274\013\346\277\003\036&\363\253<#Q)YP\262J|\244\355Ox.\02709\001G\221\221\020\341\027\200\323\005\300V\205\225O\377e\250\267\037F\361\303\316\035\025\263;\315M\027\355\275\025Q\033\347\323\220\351w\370\0069\r\255y\214l\260MK\236\360\t\314}\365\206\342.\326\222$\245n\327\3020w\002\204\301\352j\262\036\323\254/\363\371\254#\267P\2471\351\227\213\365l&KX\322)6\274\223\027\025M7\023]c\356\321F \177hZ\275\373\024%&p@9#C\247Mq\317\035M\375\236\005\230\200\207\236H\325,\357\356\031\322\025?\201B\324}Wl[{\345\364\233\317,X^\232\003\356\255\213p\250\3328*\275a\355|\205\3733\021n\333W\322C)>(\234ra\330m\272\000\306\375!\013\200\313\021{\322%5=\246\210\212-\355T\363%t\332M\247S|\262\007\tS\0258\352\241\206\356A&%\364\275\3270\3401p\r\323\211\230O\314\314o<\'\354\253\353\202\352\234 \274\277\022\335\240a\212mu\214\272\021\206\211\306\205>\006`\216S\226Lt\360`\204\274\021=\000\000\\0sS\373\007\356\357\032v\004\3114\277\n\330T\215\023h\322t3\376\374\275\271\257\240d\244j\007\272\t2\211#H.&\005\340\225\"\025\3527\257\201\214\241Z\016\002\346?\n\206\204\000\356U\231\330\037\302\252\364I\006\031\365\r\005\007tGw\026i\034\036&\306\306(\326\276`\311\270H\000\355\233\267\246\223\201{Z\2452\365Yk\331\036\312W\023\225M\212\355d\213\014\315\310G\253\253\216!=\353j\2262\326\250n\000\301\326\031\025\252v\006\312\335\032\245\025\332\237\244\245\227\375\037\017\333\230\335`h\310\241\000\000\000\000IEND\256B`\202" + encoded_image_string: "\211PNG\r\n\032\n\000\000\000\rIHDR\000\000\000 \000\000\000 \010\002\000\000\000\374\030\355\243\000\000\000sIDATx\234\355\323=\n\300 \014\005\340\027p\250\267p\324\373\332\373\345\020vn\007\367>0\204b\311\233\305/\344G\000\334\236\021Uu\005R\000\377\007\244\224\342\013||\007\2655\330BfP\215\337S`>:{_l\020\335\242\tX6-\000\032r\007G\316\000\2561\226\201\244\252/\005V\357\026\271\003\033\0149\000\232\270\003+\260\301\220\003\240y\000T\221\324V\250_v\320\000\000\000\000IEND\256B`\202" } } diff --git a/tests/expect/test_summary.test_image_with_one_channel.expect b/tests/expect/test_summary.test_image_with_one_channel.expect index 62071760..7b43f507 100644 --- a/tests/expect/test_summary.test_image_with_one_channel.expect +++ b/tests/expect/test_summary.test_image_with_one_channel.expect @@ -4,6 +4,6 @@ value { height: 8 width: 8 colorspace: 3 - encoded_image_string: "\211PNG\r\n\032\n\000\000\000\rIHDR\000\000\000\010\000\000\000\010\010\002\000\000\000Km)\334\000\000\000\311IDATx\234\005\301-\n\2050\000\000`6f\320\372\302\020\305h\321h\360\002^`aI\206\321`\022o\2417\020<\200\260#x\002\301\201\'\030\376\240 \006\205\025\005y\337\007\312\262\364>>===<<<;;;999888777666555444///...---,,,)))(((%%%$$$###\"\"\"!!! \036\036\036\035\035\035\034\034\034\033\033\033\032\032\032\031\031\031\030\030\030\026\026\026\025\025\025\023\023\023\022\022\022\021\021\021\020\020\020\017\017\017\016\016\016\013\013\013\n\n\n\010\010\010\006\006\006\005\005\005\004\004\004\003\003\003\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000!\377\013NETSCAPE2.0\003\001\377\377\000!\371\004\010\031\000\000\000,\000\000\000\000\020\000\020\000\000\010\377\000\203\240\330!\244\n\r)\022\374((\201\004\217\034LS\014l\351@\344\007\003J\221\324\254\340\002\210S\245\026O:a\370Pa\000\207&\036\206D\010\240\007\006\234N#\024\325(\244\240\210\0258 \320l\341\221\341\006\2057\034\234\374\360\204#\007\016\005-\374 `\261\'\201\t9{\300HYq\351\205\013>\211\214p\352S\245\013\0237=\322|\361!%\200#>\202,,:\202\010\205\226\037\177f\310aBg\020#\031\206\n%\t\263 \004\211\007\22248\3300\350F\226KU\006M\200\342`P\214(\223\342\\\330t L\030O~V\314\321t\351\222\203\022\020\2600x\224\240\302\2233w\\\020Y\003\340\313\022.\003rl\372D\245\222\234>>===<<<;;;999888222000...+++&&&%%%\"\"\"!!!\036\036\036\035\035\035\034\034\034\033\033\033\032\032\032\031\031\031\030\030\030\027\027\027\026\026\026\025\025\025\024\024\024\022\022\022\021\021\021\020\020\020\016\016\016\r\r\r\014\014\014\t\t\t\007\007\007\005\005\005\004\004\004\003\003\003\002\002\002\001\001\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\010\377\000\377\214\371\320\250C#\002S\216\0049\360F\017\243M\016\006\3708\201)\316!7\207h\210\220\023\204\022\224\001\025\324p\241\364\242\210\035%\216\316\034\340\243`A\210\035\026\206\274p\024\241\005\000D\031\354\204\0212G\314\237)\230\n\375`\304\341C\021.\224@Lj\322f\010\202\035\231bTY\241\201\300\006Oe\2648IRC\316\"/\tT\020jr\351O\247\020{\000I@B\305\002\225\025]\316\215P<\3304\301\313\005\031\002\206\304\270\261\340\223\016 AL\220\211\022f\214\035)5\016t\212\341\301I\032\021\217\3440id\010S\201O\202\2564\221\001I\317\226\036\025~H\262\300\302\300\0237G|$%\032\200\001\n\004$\020\0344\241sA\314\247;k:\030\210\220i\320\027\005n6P\261\222\306\002\003\200\001\300\004\004\000;" + encoded_image_string: "GIF89a\020\000\020\000\207\000\000\377\377\377\376\376\376\375\375\375\374\374\374\373\373\373\372\372\372\371\371\371\370\370\370\367\367\367\366\366\366\365\365\365\364\364\364\363\363\363\362\362\362\361\361\361\360\360\360\357\357\357\356\356\356\355\355\355\354\354\354\353\353\353\352\352\352\351\351\351\350\350\350\347\347\347\346\346\346\345\345\345\344\344\344\343\343\343\342\342\342\341\341\341\340\340\340\337\337\337\336\336\336\335\335\335\334\334\334\333\333\333\332\332\332\331\331\331\330\330\330\327\327\327\326\326\326\325\325\325\324\324\324\323\323\323\322\322\322\321\321\321\320\320\320\317\317\317\316\316\316\315\315\315\314\314\314\313\313\313\312\312\312\311\311\311\310\310\310\307\307\307\306\306\306\305\305\305\304\304\304\303\303\303\302\302\302\301\301\301\300\300\300\277\277\277\276\276\276\275\275\275\274\274\274\273\273\273\272\272\272\271\271\271\270\270\270\267\267\267\266\266\266\265\265\265\264\264\264\263\263\263\262\262\262\261\261\261\260\260\260\257\257\257\256\256\256\255\255\255\254\254\254\253\253\253\252\252\252\251\251\251\250\250\250\247\247\247\246\246\246\245\245\245\244\244\244\243\243\243\242\242\242\241\241\241\240\240\240\237\237\237\236\236\236\235\235\235\234\234\234\233\233\233\232\232\232\231\231\231\230\230\230\227\227\227\226\226\226\225\225\225\224\224\224\223\223\223\222\222\222\221\221\221\220\220\220\217\217\217\216\216\216\215\215\215\214\214\214\213\213\213\212\212\212\211\211\211\210\210\210\207\207\207\206\206\206\205\205\205\204\204\204\203\203\203\202\202\202\201\201\201\200\200\200\177\177\177~~~}}}|||{{{zzzyyyxxxwwwvvvuuutttsssrrrqqqpppooonnnmmmlllkkkjjjiiihhhgggfffeeedddcccbbbaaa```___^^^]]]\\\\\\[[[ZZZYYYXXXWWWVVVUUUTTTSSSRRRQQQPPPOOONNNMMMLLLKKKJJJIIIHHHGGGFFFEEEDDDCCCBBBAAA@@@???>>>===<<<;;;:::999888777666555444333222111000///...---,,,+++***)))(((\'\'\'&&&%%%$$$###\"\"\"!!! \037\037\037\036\036\036\035\035\035\034\034\034\033\033\033\032\032\032\031\031\031\030\030\030\027\027\027\026\026\026\025\025\025\024\024\024\023\023\023\022\022\022\021\021\021\020\020\020\017\017\017\016\016\016\r\r\r\014\014\014\013\013\013\n\n\n\t\t\t\010\010\010\007\007\007\006\006\006\005\005\005\004\004\004\003\003\003\002\002\002\001\001\001\000\000\000!\377\013NETSCAPE2.0\003\001\377\377\000!\371\004\010\031\000\000\000,\000\000\000\000\020\000\020\000\000\010\377\000\377\001\010 `\000\201\002\006~\001\013&l\030\261b\306\016 H\240`\001\203\006\016\216!K\246l\031\263f\316\036@\210 a\002\205\n\026\236A\213&m\032\265j\326.`\310\240a\003\207\016\036\256a\313\246m\033\267n\336>\200\010!b\004\211\022&\276\201\013\'n\034\271r\346N\240H\241b\005\213\026.\316\241K\247n\035\273v\356^\300\210!c\006\215\0326\336\301\213\'o\036\275z\366n\340\310\241c\007\217\036>\356\341\313\247o\037\277~\376\376\000\n$h\020\241B\206~\000\t\"d\010\221\"F\016!J\244h\021\243F\216\216 I\242d\t\223&N\036A\212$i\022\245J\226\236@\211\"e\n\225*V.a\312\244i\023\247N\236\256`\311\242e\013\227.^>\201\n%j\024\251R\246\276\200\t#f\014\2312fN\241J\245j\025\253V\256\316\240I\243f\r\2336n^\301%\212%k\026\255Z\266\336\300\211#g\016\235:vn\341\312\245k\027\257^\276\356\340\311\243g\017\037\200}\374\004\004\000!\371\004\010\031\000\000\000,\000\000\000\000\020\000\020\000\000\010\377\000\177\000\t\"d\010\221\"F\376\001\010 `\000\201\002\006\216 I\242d\t\223&N\016 H\240`\001\203\006\016\236@\211\"e\n\225*V\036@\210 a\002\205\n\026\256`\311\242e\013\227.^.`\310\240a\003\207\016\036\276\200\t#f\014\2312f>\200\010!b\004\211\022&\316\240I\243f\r\2336nN\240H\241b\005\213\026.\336\300\211#g\016\235:v^\300\210!c\006\215\0326\356\340\311\243g\017\237>~n\340\310\241c\007\217\036>~\001\013&l\030\261b\306\376\000\n$h\020\241B\206\216!K\246l\031\263f\316\016!J\244h\021\243F\216\236A\213&m\032\265j\326\036A\212$i\022\245J\226\256a\313\246m\033\267n\336.a\312\244i\023\247N\236\276\201\013\'n\034\271r\346>\201\n%j\024\251R\246\316\241K\247n\035\273v\356N\241J\245j\025\253V\256\336\301%\213\'o\036\275z\366^\301\212%k\026\255Z\266\356\341\313\247o\037\277~\376n\341\312\245k\027/\200\275|\005\004\000!\371\004\010\031\000\000\000,\000\000\000\000\020\000\020\000\000\010\377\000\377\000\n$h\020\241B\206~\000\t\"d\010\221\"F\016!J\244h\021\243F\216\216 I\242d\t\223&N\036A\212$i\022\245J\226\236@\211\"e\n\225*V.a\312\244i\023\247N\236\256`\311\242e\013\227.^>\201\n%j\024\251R\246\276\200\t#f\014\2312fN\241J\245j\025\253V\256\316\240I\243f\r\2336n^\301\212%k\026\255Z\266\336\300\211#g\016\235:vn\341\312\245k\027\257^\276\356\340\311\243g\017\237>~\376\001\010 `\000\201\002\006~\001\013&l\030\261b\306\016 H\240`\001\203\006\016\216!K\246l\031\263f\316\036@\210 a\002\205\n\026\236A\213&m\032\265j\326.`\310\240a\003\207\016\036\256a\313\246m\033\267n\336>\200\010!b\004\211\022&\276\201\013\'n\034\271r\346N\240H\241b\005\213\026.\316\241K\247n\035\273v\356^\300%\210!c\006\215\0326\336\301\213\'o\036\275z\366n\340\310\241c\007\217\036>\356\341\313\247o\037?\200\375\374\005\004\000;" } } diff --git a/tests/expect_reader.py b/tests/expect_reader.py index 43b2f7a8..946219a2 100644 --- a/tests/expect_reader.py +++ b/tests/expect_reader.py @@ -8,12 +8,6 @@ def removeWhiteChar(string): def compare_proto(str_to_compare, function_ptr): - if 'histogram' in function_ptr.id(): - return # numpy.histogram has slightly different between different version - - if 'pr_curve' in function_ptr.id(): - return # pr_curve depends on numpy.histogram - module_id = function_ptr.__class__.__module__ functionName = function_ptr.id().split('.')[-1] test_file = os.path.realpath(sys.modules[module_id].__file__) diff --git a/tests/test_pr_curve.py b/tests/test_pr_curve.py index 5a63c73d..b96ddfb7 100644 --- a/tests/test_pr_curve.py +++ b/tests/test_pr_curve.py @@ -18,7 +18,7 @@ class PRCurveTest(unittest.TestCase): def test_smoke(self): with SummaryWriter() as writer: writer.add_pr_curve('xoxo', np.random.randint(2, size=100), np.random.rand( - 100), 1) # needs tensorboard 0.4RC or later + 100), 1) writer.add_pr_curve_raw('prcurve with raw data', true_positive_counts, false_positive_counts, @@ -29,11 +29,34 @@ def test_smoke(self): 1) def test_pr_purve(self): - np.random.seed(0) - compare_proto(summary.pr_curve('tag', np.random.randint(2, size=100), np.random.rand(100), 1), self) + random_labels = np.array([0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, + 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, + 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, + 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, + 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0]) + random_probs = np.array([0.33327776, 0.30032885, 0.79012837, 0.04306813, 0.65221544, + 0.58481968, 0.28305522, 0.53795795, 0.00729739, 0.52266951, + 0.22464247, 0.11262435, 0.41573075, 0.92493992, 0.73066758, + 0.43867735, 0.27955449, 0.56975382, 0.53933028, 0.34392824, + 0.30312509, 0.81732807, 0.55408544, 0.3969487 , 0.31768033, + 0.24353266, 0.47198005, 0.19999122, 0.05788022, 0.24046305, + 0.04651082, 0.30061738, 0.78321545, 0.82670207, 0.49200517, + 0.80904619, 0.96711993, 0.3160946 , 0.01049424, 0.60108337, + 0.56508792, 0.83729429, 0.9717386 , 0.46306053, 0.80232138, + 0.24166823, 0.7393237 , 0.50820418, 0.04944932, 0.53854157, + 0.10765172, 0.84723855, 0.20518299, 0.3143431 , 0.51299074, + 0.47065695, 0.54267833, 0.1812676 , 0.06265177, 0.34110327, + 0.30915171, 0.91870169, 0.91309447, 0.31395817, 0.36780571, + 0.98297986, 0.00594547, 0.52839042, 0.70229202, 0.37779588, + 0.15207045, 0.59759632, 0.72397032, 0.71502195, 0.90135725, + 0.43970107, 0.17123532, 0.08785938, 0.04986818, 0.62702444, + 0.69171023, 0.30537792, 0.30285433, 0.27124347, 0.27693729, + 0.7136039 , 0.48022489, 0.20916285, 0.2018599 , 0.92401008, + 0.30189681, 0.46862626, 0.96353024, 0.30468533, 0.68281294, + 0.30623562, 0.40795975, 0.76824531, 0.89824215, 0.69845035], dtype=np.float16) + compare_proto(summary.pr_curve('tag', random_labels, random_probs, 1), self) def test_pr_purve_raw(self): - np.random.seed(0) compare_proto(summary.pr_curve_raw('prcurve with raw data', true_positive_counts, false_positive_counts, diff --git a/tests/test_summary.py b/tests/test_summary.py index fb043343..685b45fb 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -1,19 +1,22 @@ from __future__ import absolute_import, division, print_function, unicode_literals from tensorboardX import summary -from .expect_reader import compare_proto +from .expect_reader import compare_proto, write_proto import numpy as np import pytest import unittest -np.random.seed(0) # compare_proto = write_proto # massive update expect +def tensor_N(shape, dtype=float): + numel = np.prod(shape) + x = (np.arange(numel, dtype=dtype)).reshape(shape) + return x class SummaryTest(unittest.TestCase): def test_uint8_image(self): ''' Tests that uint8 image (pixel values in [0, 255]) is not changed ''' - test_image = np.random.randint(0, 256, size=(3, 32, 32), dtype=np.uint8) + test_image = tensor_N(shape=(3, 32, 32), dtype=np.uint8) scale_factor = summary._calc_scale_factor(test_image) assert scale_factor == 1, 'Values are already in [0, 255], scale factor should be 1' @@ -22,7 +25,7 @@ def test_float32_image(self): Tests that float32 image (pixel values in [0, 1]) are scaled correctly to [0, 255] ''' - test_image = np.random.rand(3, 32, 32).astype(np.float32) + test_image = tensor_N(shape=(3, 32, 32)) scale_factor = summary._calc_scale_factor(test_image) assert scale_factor == 255, 'Values are in [0, 1], scale factor should be 255' @@ -37,50 +40,41 @@ def test_empty_input(self): def test_image_with_boxes(self): compare_proto(summary.image_boxes('dummy', - np.random.rand(3, 32, 32).astype(np.float32), + tensor_N(shape=(3, 32, 32)), np.array([[10, 10, 40, 40]])), self) def test_image_with_one_channel(self): - np.random.seed(0) - compare_proto(summary.image('dummy', np.random.rand(1, 8, 8).astype(np.float32), dataformats='CHW'), self) + compare_proto(summary.image('dummy', tensor_N(shape=(1, 8, 8)), dataformats='CHW'), self) def test_image_with_one_channel_batched(self): - np.random.seed(0) - compare_proto(summary.image('dummy', np.random.rand(2, 1, 8, 8).astype(np.float32), dataformats='NCHW'), self) + compare_proto(summary.image('dummy', tensor_N(shape=(2, 1, 8, 8)), dataformats='NCHW'), self) def test_image_with_3_channel_batched(self): - np.random.seed(0) - compare_proto(summary.image('dummy', np.random.rand(2, 3, 8, 8).astype(np.float32), dataformats='NCHW'), self) + compare_proto(summary.image('dummy', tensor_N(shape=(2, 3, 8, 8)), dataformats='NCHW'), self) def test_image_without_channel(self): - np.random.seed(0) - compare_proto(summary.image('dummy', np.random.rand(8, 8).astype(np.float32), dataformats='HW'), self) + compare_proto(summary.image('dummy', tensor_N(shape=(8, 8)), dataformats='HW'), self) def test_video(self): try: import moviepy except ImportError: return - np.random.seed(0) - compare_proto(summary.video('dummy', np.random.rand(4, 3, 1, 8, 8).astype(np.float32)), self) - summary.video('dummy', np.random.rand(16, 48, 1, 28, 28).astype(np.float32)) - summary.video('dummy', np.random.rand(20, 7, 1, 8, 8).astype(np.float32)) + compare_proto(summary.video('dummy', tensor_N(shape=(4, 3, 1, 8, 8))), self) + summary.video('dummy', tensor_N(shape=(16, 48, 1, 28, 28))) + summary.video('dummy', tensor_N(shape=(20, 7, 1, 8, 8))) def test_audio(self): - np.random.seed(0) - compare_proto(summary.audio('dummy', np.random.rand(42)), self) + compare_proto(summary.audio('dummy', tensor_N(shape=(42,))), self) def test_text(self): compare_proto(summary.text('dummy', 'text 123'), self) def test_histogram_auto(self): - np.random.seed(0) - compare_proto(summary.histogram('dummy', np.random.rand(1024), bins='auto', max_bins=5), self) + compare_proto(summary.histogram('dummy', tensor_N(shape=(1024,)), bins='auto', max_bins=5), self) def test_histogram_fd(self): - np.random.seed(0) - compare_proto(summary.histogram('dummy', np.random.rand(1024), bins='fd', max_bins=5), self) + compare_proto(summary.histogram('dummy', tensor_N(shape=(1024,)), bins='fd', max_bins=5), self) def test_histogram_doane(self): - np.random.seed(0) - compare_proto(summary.histogram('dummy', np.random.rand(1024), bins='doane', max_bins=5), self) + compare_proto(summary.histogram('dummy', tensor_N(shape=(1024,)), bins='doane', max_bins=5), self)