提交 fe073d1f 编写于 作者: D dangqingqing

Add style check and remove 'using namespace'

上级 4d997823
......@@ -43,6 +43,7 @@ option(WITH_SWIG_PY "Compile PaddlePaddle with py PaddlePaddle prediction api" $
option(ON_TRAVIS "Running test on travis-ci or not." OFF)
option(ON_COVERALLS "Generating code coverage data on coveralls or not." OFF)
option(COVERALLS_UPLOAD "Uploading the generated coveralls json." ON)
option(USE_OPENCV "Compile PaddlePaddle with opencv" OFF)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
......
......@@ -42,3 +42,6 @@ add_library(DeJpeg SHARED ${DEJPEG_SOURCES})
target_compile_options(DeJpeg BEFORE PRIVATE ${BUILD_PRIVATE_FLAGS})
target_link_libraries(DeJpeg ${DEJPEG_LINKER_LIBS})
set_target_properties(DeJpeg PROPERTIES PREFIX "")
add_style_check_target(DeJpeg ${DEJPEG_SOURCES})
add_style_check_target(DeJpeg ${DEJPEG_HEADER})
......@@ -51,7 +51,7 @@ DataTransformer::DataTransformer(int threadNum,
}
numThreads_ = threadNum;
syncThreadPool_.reset(new SyncThreadPool(numThreads_, false));
syncThreadPool_.reset(new paddle::SyncThreadPool(numThreads_, false));
}
void DataTransformer::loadMean(float* values) {
......@@ -66,7 +66,7 @@ void DataTransformer::loadMean(float* values) {
void DataTransformer::startFetching(const char* src,
const int size,
float* trg) {
vector<char> imbuf(src, src + size);
std::vector<char> imbuf(src, src + size);
int cvFlag = (isColor_ ? CV_LOAD_IMAGE_COLOR : CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat im = cv::imdecode(cv::Mat(imbuf), cvFlag);
if (!im.data) {
......@@ -83,7 +83,7 @@ int DataTransformer::Rand(int min, int max) {
return dist(rng);
}
void DataTransformer::transform(Mat& cvImgOri, float* target) {
void DataTransformer::transform(cv::Mat& cvImgOri, float* target) {
const int imgChannels = cvImgOri.channels();
const int imgHeight = cvImgOri.rows;
const int imgWidth = cvImgOri.cols;
......@@ -152,7 +152,9 @@ void DataTransformer::transform(Mat& cvImgOri, float* target) {
} // target: BGR
}
void DataTransformer::start(vector<char*>& data, int* datalen, int* labels) {
void DataTransformer::start(std::vector<char*>& data,
int* datalen,
int* labels) {
auto job = [&](int tid, int numThreads) {
for (size_t i = tid; i < data.size(); i += numThreads) {
DataTypePtr ret = prefetchFree_.dequeue();
......
......@@ -12,6 +12,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#ifndef DATATRANSFORMER_H_
#define DATATRANSFORMER_H_
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
......@@ -21,9 +24,6 @@ limitations under the License. */
#include "paddle/utils/Thread.h"
using namespace cv;
using namespace paddle;
/**
* This is an image processing module with OpenCV, such as
* resizing, scaling, mirroring, substracting the image mean...
......@@ -57,7 +57,7 @@ public:
* @param data Data containing the image string to be transformed.
* @param label The label of input image.
*/
void start(vector<char*>& data, int* datalen, int* labels);
void start(std::vector<char*>& data, int* datalen, int* labels);
/**
* @brief Applies the transformation on one image Mat.
......@@ -65,7 +65,7 @@ public:
* @param img The input img to be transformed.
* @param target target is used to save the transformed data.
*/
void transform(Mat& img, float* target);
void transform(cv::Mat& img, float* target);
/**
* @brief Decode the image string, then calls transform() function.
......@@ -114,8 +114,9 @@ private:
typedef std::pair<float*, int> DataType;
typedef std::shared_ptr<DataType> DataTypePtr;
std::vector<DataTypePtr> prefetch_;
std::unique_ptr<SyncThreadPool> syncThreadPool_;
BlockingQueue<DataTypePtr> prefetchFree_;
BlockingQueue<DataTypePtr> prefetchFull_;
std::unique_ptr<paddle::SyncThreadPool> syncThreadPool_;
paddle::BlockingQueue<DataTypePtr> prefetchFree_;
paddle::BlockingQueue<DataTypePtr> prefetchFull_;
}; // class DataTransformer
#endif // DATATRANSFORMER_H_
......@@ -23,8 +23,6 @@ limitations under the License. */
#include "DataTransformer.h"
using namespace boost::python;
/**
* DecodeJpeg is an image processing API for interfacing Python and C++
* code DataTransformer, which used OpenCV and multi-threads to accelerate
......@@ -83,7 +81,7 @@ public:
* It's type is numpy.array with int32.
*/
void start(boost::python::list& pysrc, PyObject* pydlen, PyObject* pylabel) {
vector<char*> data;
std::vector<char*> data;
int num = len(pysrc);
for (int t = 0; t < num; ++t) {
char* src = boost::python::extract<char*>(pysrc[t]);
......@@ -169,8 +167,9 @@ static void initPython() {
*/
BOOST_PYTHON_MODULE(DeJpeg) {
initPython();
class_<DecodeJpeg>("DecodeJpeg",
init<int, int, bool, bool, int, int, int, PyObject*>())
boost::python::class_<DecodeJpeg>(
"DecodeJpeg",
boost::python::init<int, int, bool, bool, int, int, int, PyObject*>())
.def("start", &DecodeJpeg::start)
.def("get", &DecodeJpeg::get);
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册