提交 37c04470 编写于 作者: 朔-望's avatar 朔-望

Merge remote-tracking branch 'upstream/develop' into develop

......@@ -54,3 +54,5 @@ paddle-mobile.cbp
cmake-build-debug/
test/models/
\ No newline at end of file
......@@ -46,12 +46,4 @@ ADD_LIBRARY(paddle-mobile-static STATIC ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
target_link_libraries(paddle-mobile-static protobuf-lite openblas)
#add_dependencies(paddle-mobile openblas_proj)
# gen test
ADD_EXECUTABLE(paddle-mobile-test test/main.cpp test/test_helper.h
test/elementwise_add_op_test.h test/test_include.h
test/mul_op_test.h)
target_link_libraries(paddle-mobile-test paddle-mobile)
# gen test log
ADD_EXECUTABLE(test-log test/unit-test/test_log.cpp)
target_link_libraries(test-log paddle-mobile)
add_subdirectory(test)
\ No newline at end of file
......@@ -18,6 +18,8 @@ SOFTWARE.
#pragma once
#include <map>
#include "attribute.h"
#include "block_desc.h"
#include "common/type_define.h"
......@@ -29,10 +31,18 @@ SOFTWARE.
#include "scope.h"
#include "tensor.h"
#include "variable.h"
#include <map>
namespace paddle_mobile {
namespace framework {
static std::unordered_map<std::string, std::vector<std::string>>
op_input_output_key = {
{"conv2d", {"Input", "Output"}}, {"relu", {"X", "Out"}},
{"softmax", {"X", "Out"}}, {"mul", {"X", "Out"}},
{"elementwise_add", {"X", "Out"}}, {"pool2d", {"X", "Out"}},
{"batch_norm", {"X", "Y"}}, {"lrn", {"X", "Out"}},
{"concat", {"X", "Out"}},
};
template <typename Dtype> class OperatorBase : PaddleMobileObject {
public:
......
......@@ -17,7 +17,6 @@ SOFTWARE.
==============================================================================*/
#include <fstream>
//#include <iostream>
#include "common/log.h"
#include "framework/framework.pb.h"
......@@ -42,27 +41,26 @@ namespace paddle_mobile {
template <typename Dtype, Precision P>
void Loader<Dtype, P>::LoadVar(framework::LoDTensor *tensor,
const std::string &file_path) {
LOG(kLOG_DEBUG) << " to load " << file_path;
// LOG(kLOG_DEBUG) << " to load " << file_path;
// Log(kLOG_DEBUG) << "123";
std::ifstream is(file_path);
std::streampos pos = is.tellg(); // save current position
is.seekg(0, std::ios::end);
LOG(kLOG_DEBUG) << " file length = " << is.tellg();
// LOG(kLOG_DEBUG) << " file length = " << is.tellg();
is.seekg(pos); // restore saved position
// 1. version
uint32_t version;
is.read(reinterpret_cast<char *>(&version), sizeof(version));
LOG(kLOG_INFO) << " version: " << version;
// LOG(kLOG_INFO) << " version: " << version;
// 2 Lod information
uint64_t lod_level;
is.read(reinterpret_cast<char *>(&lod_level), sizeof(lod_level));
LOG(kLOG_DEBUG) << " load level: " << lod_level;
LOG(kLOG_DEBUG) << " lod info: ";
// LOG(kLOG_DEBUG) << " load level: " << lod_level;
// LOG(kLOG_DEBUG) << " lod info: ";
auto &lod = *tensor->mutable_lod();
lod.resize(lod_level);
for (uint64_t i = 0; i < lod_level; ++i) {
......@@ -197,32 +195,26 @@ namespace paddle_mobile {
#ifdef PADDLE_MOBILE_DEBUG
for (int i = 0; i < program_desc_proto.blocks().size(); ++i) {
framework::proto::BlockDesc block = program_desc_proto.blocks()[i];
// std::cout << "block: " << block.idx() << std::endl;
LOG(kLOG_DEBUG) << "block: " << block.idx();
for (int j = 0; j < block.ops().size(); ++j) {
framework::proto::OpDesc op = block.ops()[j];
// std::cout << " op: " << op.type() << std::endl;
LOG(kLOG_DEBUG1) << " op: " << op.type();
for (int m = 0; m < op.inputs_size(); ++m) {
const framework::proto::OpDesc::Var &var = op.inputs(m);
// std::cout << " input parameter: " <<
// var.parameter() <<
// std::endl;
LOG(kLOG_DEBUG2) << " input parameter: "
<< var.parameter();
for (int n = 0; n < var.arguments().size(); ++n) {
// std::cout << " argument - " <<
// var.arguments()[n] <<
// std::endl;
LOG(kLOG_DEBUG3) << " argument - "
<< var.arguments()[n];
}
}
for (int y = 0; y < op.outputs_size(); ++y) {
const framework::proto::OpDesc::Var &var = op.outputs(y);
// std::cout << " output parameter: " <<
// var.parameter() <<
// std::endl;
LOG(kLOG_DEBUG2) << " out parameter: " << var.parameter();
for (int z = 0; z < var.arguments().size(); ++z) {
// std::cout << " argument - " <<
// var.arguments()[z] <<
// std::endl;
LOG(kLOG_DEBUG3) << " argument - "
<< var.arguments()[z];
}
}
......
# gen test
ADD_EXECUTABLE(paddle-mobile-test main.cpp test_helper.h elementwise_add_op_test.h test_include.h mul_op_test.h)
target_link_libraries(paddle-mobile-test paddle-mobile)
# gen test
ADD_EXECUTABLE(test-conv-op operators/test_cov_op.cpp test_helper.h test_include.h)
target_link_libraries(test-conv-op paddle-mobile)
# gen test log
ADD_EXECUTABLE(test-log common/test_log.cpp)
target_link_libraries(test-log paddle-mobile)
# gen test log
ADD_EXECUTABLE(test-load framework/test_load.cpp)
target_link_libraries(test-load paddle-mobile)
\ No newline at end of file
......@@ -19,18 +19,19 @@ SOFTWARE.
#include "common/log.h"
int main() {
DLOGF("DASJFDAFJ%d -- %f", 12345, 344.234);
LOGF( paddle_mobile::kLOG_DEBUG, "DASJFDAFJ%d -- %f", 12345, 344.234);
LOG(paddle_mobile::kLOG_DEBUG) << "test debug" << " next log";
LOG(paddle_mobile::kLOG_DEBUG1) << "test debug1"
<< " next log";
LOG(paddle_mobile::kLOG_DEBUG2) << "test debug2"
<< " next log";
DLOG << "test DLOG";
LOG(paddle_mobile::kLOG_ERROR) << " error occur !";
return 0;
......
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
==============================================================================*/
#include "io.h"
int main() {
paddle_mobile::Loader<paddle_mobile::CPU> loader;
//../../../test/models/googlenet
//../../../test/models/mobilenet
auto program = loader.Load(std::string("../../../test/models/mobilenet"));
return 0;
}
\ No newline at end of file
......@@ -17,9 +17,9 @@ SOFTWARE.
==============================================================================*/
#include "elementwise_add_op_test.h"
#include "mul_op_test.h"
#include "framework/executor.h"
#include "io.h"
#include "mul_op_test.h"
#include "test_helper.h"
//
......@@ -38,6 +38,7 @@ SOFTWARE.
//}
int main() {
std::string data_set = "cifar10";
//
// if (data_set == "cifar10") {
......
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
==============================================================================*/
#include "../test_helper.h"
#include "framework/executor.h"
#include "io.h"
int main() {
std::string data_set = "cifar10";
//
// if (data_set == "cifar10") {
// SetupTensor<float>(&input, {FLAGS_batch_size, 3, 32, 32},
// static_cast<float>(0), static_cast<float>(1));
// } else if (data_set == "imagenet") {
// SetupTensor<float>(&input, {FLAGS_batch_size, 3, 224, 224},
// static_cast<float>(0), static_cast<float>(1));
// } else {
// LOG(FATAL) << "Only cifar10 or imagenet is supported.";
// }
paddle_mobile::Loader<paddle_mobile::CPU> loader;
auto program = loader.Load(std::string("../../../test/models/googlenet"));
paddle_mobile::framework::Executor<paddle_mobile::CPU> executor(program);
paddle_mobile::framework::Tensor input;
SetupTensor<float>(&input, {1, 3, 32, 32}, static_cast<float>(0),
static_cast<float>(1));
float *input_ptr = input.data<float>();
for (int i = 0; i < input.numel(); ++i) {
// std::cout << input_ptr[i] << std::endl;
}
// std::cout << "input: " << input.memory_size() << std::endl;
// std::cout << "input: " << input.numel() << std::endl;
auto output = executor.predict(input);
// std::cout << "output: " << output->memory_size() << std::endl;
// std::cout << "output: " << output->numel() << std::endl;
// float* output_ptr = output->data<float>();
// for (int j = 0; j < output->numel(); ++j) {
// std::cout << " value of output: " << output_ptr[j] << std::endl;
//
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册