From a38db3cb996885162971bb650f4f0bcc63e745d4 Mon Sep 17 00:00:00 2001 From: wopeizl Date: Mon, 11 Mar 2019 13:59:38 +0800 Subject: [PATCH] Fixrecordio (#16124) * fix recordio on win test=develop * test=develop * test=develop * fix code style test=develop * test=develop --- paddle/fluid/pybind/recordio.cc | 2 +- paddle/fluid/recordio/scanner.cc | 4 +++- python/paddle/fluid/tests/unittests/test_accuracy_op.py | 4 ++-- python/paddle/fluid/tests/unittests/test_random_crop_op.py | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/pybind/recordio.cc b/paddle/fluid/pybind/recordio.cc index f83b026d4..32caf4bed 100644 --- a/paddle/fluid/pybind/recordio.cc +++ b/paddle/fluid/pybind/recordio.cc @@ -31,7 +31,7 @@ class RecordIOWriter { RecordIOWriter(const std::string& filename, recordio::Compressor compressor, size_t max_num_record) : closed_(false), - stream_(filename), + stream_(filename, std::ios::binary), writer_(&stream_, compressor, max_num_record) {} void AppendTensor(const framework::LoDTensor& tensor) { diff --git a/paddle/fluid/recordio/scanner.cc b/paddle/fluid/recordio/scanner.cc index a0a2f9842..b06c274ad 100644 --- a/paddle/fluid/recordio/scanner.cc +++ b/paddle/fluid/recordio/scanner.cc @@ -15,6 +15,7 @@ #include "paddle/fluid/recordio/scanner.h" #include +#include #include "paddle/fluid/platform/enforce.h" @@ -27,7 +28,8 @@ Scanner::Scanner(std::unique_ptr &&stream) } Scanner::Scanner(const std::string &filename) - : stream_(new std::ifstream(filename)), parser_(*stream_) { + : stream_(new std::ifstream(filename, std::ios::in | std::ios::binary)), + parser_(*stream_) { PADDLE_ENFORCE(static_cast(*stream_), "Cannot open file %s", filename); Reset(); } diff --git a/python/paddle/fluid/tests/unittests/test_accuracy_op.py b/python/paddle/fluid/tests/unittests/test_accuracy_op.py index 5257b0be6..b57aaeb52 100644 --- a/python/paddle/fluid/tests/unittests/test_accuracy_op.py +++ b/python/paddle/fluid/tests/unittests/test_accuracy_op.py @@ -26,8 +26,8 @@ class TestAccuracyOp(OpTest): self.init_dtype() n = 8192 infer = np.random.random((n, 1)).astype(self.dtype) - indices = np.random.randint(0, 2, (n, 1)) - label = np.random.randint(0, 2, (n, 1)) + indices = np.random.randint(0, 2, (n, 1)).astype('int64') + label = np.random.randint(0, 2, (n, 1)).astype('int64') self.inputs = {'Out': infer, 'Indices': indices, "Label": label} num_correct = 0 for rowid in range(n): diff --git a/python/paddle/fluid/tests/unittests/test_random_crop_op.py b/python/paddle/fluid/tests/unittests/test_random_crop_op.py index f29dddff7..db65b9e3e 100644 --- a/python/paddle/fluid/tests/unittests/test_random_crop_op.py +++ b/python/paddle/fluid/tests/unittests/test_random_crop_op.py @@ -31,7 +31,7 @@ class TestRandomCropOp(OpTest): np.array([[6, 7, 8], [10, 11, 12]]).astype(np.int32) ] self.op_type = "random_crop" - self.inputs = {'X': to_crop, 'Seed': np.array([10])} + self.inputs = {'X': to_crop, 'Seed': np.array([10]).astype('int64')} self.outputs = {'Out': np.array([]), 'SeedOut': np.array([])} self.attrs = {'shape': [2, 3]} -- GitLab