Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 3.4 #16734

Merged
merged 18 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
98db891
using argv[0] represent binary executable files' name in help() function
MoonChasing Feb 23, 2020
8559237
ONNX: upsample subgraph fusion added
ashishkrshrivastava Feb 13, 2020
599a595
Merge pull request #16573 from ashishkrshrivastava:opencvonnx
alalek Feb 29, 2020
9214103
Merge pull request #16652 from MoonChasing:master
alalek Mar 1, 2020
b1b78ae
Skipped ResizeUnfused test on Builder API
l-bat Mar 2, 2020
a5ca5f6
Merge pull request #16716 from l-bat:skip_resize_ie
alalek Mar 2, 2020
4d0f135
Merge pull request #16700 from alalek:fix_core_matexpr_size_gemm
alalek Mar 2, 2020
219ef95
MSMF: fixed issue with camera format selection
mshabunin Mar 2, 2020
e18d5e9
Gather-Cast, Mul-Cast fusion
ashishkrshrivastava Mar 1, 2020
0b85d0e
Merge pull request #16721 from mshabunin:fix-msmf-format
alalek Mar 3, 2020
57cf120
Merge pull request #16709 from ashishkrshrivastava:cvonnx
alalek Mar 3, 2020
0aa5391
Use argument value for 'mat' in call to format for vector_mat and vec…
Oct 23, 2019
90ec651
test: Add test to verify correct mat substitution into the template …
VadimLevin Mar 3, 2020
9ed1332
Merge pull request #16722 from l-bat:reshape_opset_11
l-bat Mar 4, 2020
da6ad1c
Merge pull request #15765 from zachlowry:patch-1
alalek Mar 4, 2020
fd09413
Merge pull request #16731 from alalek:issue_16708
alalek Mar 4, 2020
4f288a1
Merge pull request #16704 from alalek:core_log_once_log_if
alalek Mar 4, 2020
d4a17da
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
alalek Mar 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
91 changes: 78 additions & 13 deletions modules/core/include/opencv2/core/utils/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,16 @@ struct LogTagAuto
// non-null. Do not re-define.
#define CV_LOGTAG_GLOBAL cv::utils::logging::internal::getGlobalLogTag()

#define CV_LOG_WITH_TAG(tag, msgLevel, ...) \
#define CV_LOG_WITH_TAG(tag, msgLevel, extra_check0, extra_check1, ...) \
for(;;) { \
extra_check0; \
const auto cv_temp_msglevel = (cv::utils::logging::LogLevel)(msgLevel); \
if (cv_temp_msglevel >= (CV_LOG_STRIP_LEVEL)) break; \
auto cv_temp_logtagptr = CV_LOGTAG_PTR_CAST(CV_LOGTAG_EXPAND_NAME(tag)); \
if (!cv_temp_logtagptr) cv_temp_logtagptr = CV_LOGTAG_PTR_CAST(CV_LOGTAG_FALLBACK); \
if (!cv_temp_logtagptr) cv_temp_logtagptr = CV_LOGTAG_PTR_CAST(CV_LOGTAG_GLOBAL); \
if (cv_temp_logtagptr && (cv_temp_msglevel > cv_temp_logtagptr->level)) break; \
extra_check1; \
std::stringstream cv_temp_logstream; \
cv_temp_logstream << __VA_ARGS__; \
cv::utils::logging::internal::writeLogMessageEx( \
Expand All @@ -124,28 +126,91 @@ struct LogTagAuto
break; \
}

#define CV_LOG_FATAL(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_FATAL, __VA_ARGS__)
#define CV_LOG_ERROR(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_ERROR, __VA_ARGS__)
#define CV_LOG_WARNING(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_WARNING, __VA_ARGS__)
#define CV_LOG_INFO(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_INFO, __VA_ARGS__)
#define CV_LOG_DEBUG(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_DEBUG, __VA_ARGS__)
#define CV_LOG_VERBOSE(tag, v, ...) CV_LOG_WITH_TAG(tag, (cv::utils::logging::LOG_LEVEL_VERBOSE + (int)(v)), __VA_ARGS__)
#define CV_LOG_FATAL(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_FATAL, , , __VA_ARGS__)
#define CV_LOG_ERROR(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_ERROR, , , __VA_ARGS__)
#define CV_LOG_WARNING(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_WARNING, , , __VA_ARGS__)
#define CV_LOG_INFO(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_INFO, , , __VA_ARGS__)
#define CV_LOG_DEBUG(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_DEBUG, , , __VA_ARGS__)
#define CV_LOG_VERBOSE(tag, v, ...) CV_LOG_WITH_TAG(tag, (cv::utils::logging::LOG_LEVEL_VERBOSE + (int)(v)), , , __VA_ARGS__)

#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_INFO
# undef CV_LOG_INFO
# define CV_LOG_INFO(tag, ...)
#undef CV_LOG_INFO
#define CV_LOG_INFO(tag, ...)
#endif

#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_DEBUG
# undef CV_LOG_DEBUG
# define CV_LOG_DEBUG(tag, ...)
#undef CV_LOG_DEBUG
#define CV_LOG_DEBUG(tag, ...)
#endif

#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_VERBOSE
# undef CV_LOG_VERBOSE
# define CV_LOG_VERBOSE(tag, v, ...)
#undef CV_LOG_VERBOSE
#define CV_LOG_VERBOSE(tag, v, ...)
#endif

//! @cond IGNORED
#define CV__LOG_ONCE_CHECK_PRE \
static bool _cv_log_once_ ## __LINE__ = false; \
if (_cv_log_once_ ## __LINE__) break;

#define CV__LOG_ONCE_CHECK_POST \
_cv_log_once_ ## __LINE__ = true;

#define CV__LOG_IF_CHECK(logging_cond) \
if (!(logging_cond)) break;

//! @endcond


// CV_LOG_ONCE_XXX macros

#define CV_LOG_ONCE_ERROR(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_ERROR, CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, __VA_ARGS__)
#define CV_LOG_ONCE_WARNING(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_WARNING, CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, __VA_ARGS__)
#define CV_LOG_ONCE_INFO(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_INFO, CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, __VA_ARGS__)
#define CV_LOG_ONCE_DEBUG(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_DEBUG, CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, __VA_ARGS__)
#define CV_LOG_ONCE_VERBOSE(tag, v, ...) CV_LOG_WITH_TAG(tag, (cv::utils::logging::LOG_LEVEL_VERBOSE + (int)(v)), CV__LOG_ONCE_CHECK_PRE, CV__LOG_ONCE_CHECK_POST, __VA_ARGS__)

#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_INFO
#undef CV_LOG_ONCE_INFO
#define CV_LOG_ONCE_INFO(tag, ...)
#endif

#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_DEBUG
#undef CV_LOG_ONCE_DEBUG
#define CV_LOG_ONCE_DEBUG(tag, ...)
#endif

#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_VERBOSE
#undef CV_LOG_ONCE_VERBOSE
#define CV_LOG_ONCE_VERBOSE(tag, v, ...)
#endif


// CV_LOG_IF_XXX macros

#define CV_LOG_IF_FATAL(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_FATAL, , CV__LOG_IF_CHECK(logging_cond), __VA_ARGS__)
#define CV_LOG_IF_ERROR(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_ERROR, , CV__LOG_IF_CHECK(logging_cond), __VA_ARGS__)
#define CV_LOG_IF_WARNING(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_WARNING, , CV__LOG_IF_CHECK(logging_cond), __VA_ARGS__)
#define CV_LOG_IF_INFO(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_INFO, , CV__LOG_IF_CHECK(logging_cond), __VA_ARGS__)
#define CV_LOG_IF_DEBUG(tag, logging_cond, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_DEBUG, , CV__LOG_IF_CHECK(logging_cond), __VA_ARGS__)
#define CV_LOG_IF_VERBOSE(tag, v, logging_cond, ...) CV_LOG_WITH_TAG(tag, (cv::utils::logging::LOG_LEVEL_VERBOSE + (int)(v)), , CV__LOG_IF_CHECK(logging_cond), __VA_ARGS__)

#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_INFO
#undef CV_LOG_IF_INFO
#define CV_LOG_IF_INFO(tag, logging_cond, ...)
#endif

#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_DEBUG
#undef CV_LOG_IF_DEBUG
#define CV_LOG_IF_DEBUG(tag, logging_cond, ...)
#endif

#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_VERBOSE
#undef CV_LOG_IF_VERBOSE
#define CV_LOG_IF_VERBOSE(tag, v, logging_cond, ...)
#endif


//! @}

}}} // namespace
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ void writeLogMessage(LogLevel logLevel, const char* message)
case LOG_LEVEL_INFO: ss << "[ INFO:" << threadID << "] " << message << std::endl; break;
case LOG_LEVEL_DEBUG: ss << "[DEBUG:" << threadID << "] " << message << std::endl; break;
case LOG_LEVEL_VERBOSE: ss << message << std::endl; break;
default:
return;
case LOG_LEVEL_SILENT: return; // avoid compiler warning about incomplete switch
case ENUM_LOG_LEVEL_FORCE_INT: return; // avoid compiler warning about incomplete switch
}
#ifdef __ANDROID__
int android_logLevel = ANDROID_LOG_INFO;
Expand Down
13 changes: 10 additions & 3 deletions modules/core/src/matrix_expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,17 @@ class MatOp_GEMM CV_FINAL : public MatOp

void transpose(const MatExpr& expr, MatExpr& res) const CV_OVERRIDE;

Size size(const MatExpr& expr) const CV_OVERRIDE
{
return Size(
(expr.flags & GEMM_2_T) ? expr.b.rows : expr.b.cols,
(expr.flags & GEMM_1_T) ? expr.a.cols : expr.a.rows
);
}

static void makeExpr(MatExpr& res, int flags, const Mat& a, const Mat& b,
double alpha=1, const Mat& c=Mat(), double beta=1);

};

static MatOp_GEMM g_MatOp_GEMM;
Expand Down Expand Up @@ -199,7 +208,7 @@ static inline bool isReciprocal(const MatExpr& e) { return isBin(e,'/') && (!e.b
static inline bool isT(const MatExpr& e) { return e.op == &g_MatOp_T; }
static inline bool isInv(const MatExpr& e) { return e.op == &g_MatOp_Invert; }
static inline bool isSolve(const MatExpr& e) { return e.op == &g_MatOp_Solve; }
static inline bool isGEMM(const MatExpr& e) { return e.op == &g_MatOp_GEMM; }
//static inline bool isGEMM(const MatExpr& e) { return e.op == &g_MatOp_GEMM; }
static inline bool isMatProd(const MatExpr& e) { return e.op == &g_MatOp_GEMM && (!e.c.data || e.beta == 0); }
static inline bool isInitializer(const MatExpr& e) { return e.op == getGlobalMatOpInitializer(); }

Expand Down Expand Up @@ -1240,8 +1249,6 @@ Size MatExpr::size() const
{
if( isT(*this) || isInv(*this) )
return Size(a.rows, a.cols);
if( isGEMM(*this) )
return Size(b.cols, a.rows);
if( isSolve(*this) )
return Size(b.cols, a.cols);
if( isInitializer(*this) )
Expand Down
23 changes: 23 additions & 0 deletions modules/core/test/test_mat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,29 @@ TEST(Core_MatExpr, issue_16655)
<< "Mat: CV_8UC3 != " << typeToString(ab_mat.type());
}

TEST(Core_MatExpr, issue_16689)
{
Mat a(Size(10, 5), CV_32FC1, 5);
Mat b(Size(10, 5), CV_32FC1, 2);
Mat bt(Size(5, 10), CV_32FC1, 3);
{
MatExpr r = a * bt; // gemm
EXPECT_EQ(Mat(r).size(), r.size()) << "[10x5] x [5x10] => [5x5]";
}
{
MatExpr r = a * b.t(); // gemm
EXPECT_EQ(Mat(r).size(), r.size()) << "[10x5] x [10x5].t() => [5x5]";
}
{
MatExpr r = a.t() * b; // gemm
EXPECT_EQ(Mat(r).size(), r.size()) << "[10x5].t() x [10x5] => [10x10]";
}
{
MatExpr r = a.t() * bt.t(); // gemm
EXPECT_EQ(Mat(r).size(), r.size()) << "[10x5].t() x [5x10].t() => [10x10]";
}
}

#ifdef HAVE_EIGEN
TEST(Core_Eigen, eigen2cv_check_Mat_type)
{
Expand Down
50 changes: 50 additions & 0 deletions modules/core/test/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
#include "opencv2/core/utils/logger.defines.hpp"
#undef CV_LOG_STRIP_LEVEL
#define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_VERBOSE + 1
#include "opencv2/core/utils/logger.hpp"
#include "opencv2/core/utils/buffer_area.private.hpp"

Expand Down Expand Up @@ -287,6 +290,53 @@ TEST(CommandLineParser, testScalar)
EXPECT_EQ(parser.get<Scalar>("s5"), Scalar(5, -4, 3, 2));
}


TEST(Logger, DISABLED_message)
{
int id = 42;
CV_LOG_VERBOSE(NULL, 0, "Verbose message: " << id);
CV_LOG_VERBOSE(NULL, 1, "Verbose message: " << id);
CV_LOG_DEBUG(NULL, "Debug message: " << id);
CV_LOG_INFO(NULL, "Info message: " << id);
CV_LOG_WARNING(NULL, "Warning message: " << id);
CV_LOG_ERROR(NULL, "Error message: " << id);
CV_LOG_FATAL(NULL, "Fatal message: " << id);
}

static int testLoggerMessageOnce(int id)
{
CV_LOG_ONCE_VERBOSE(NULL, 0, "Verbose message: " << id++);
CV_LOG_ONCE_VERBOSE(NULL, 1, "Verbose message: " << id++);
CV_LOG_ONCE_DEBUG(NULL, "Debug message: " << id++);
CV_LOG_ONCE_INFO(NULL, "Info message: " << id++);
CV_LOG_ONCE_WARNING(NULL, "Warning message: " << id++);
CV_LOG_ONCE_ERROR(NULL, "Error message: " << id++);
// doesn't make sense: CV_LOG_ONCE_FATAL
return id;
}
TEST(Logger, DISABLED_message_once)
{
int check_id_first = testLoggerMessageOnce(42);
EXPECT_GT(check_id_first, 42);
int check_id_second = testLoggerMessageOnce(0);
EXPECT_EQ(0, check_id_second);
}

TEST(Logger, DISABLED_message_if)
{
for (int i = 0; i < 100; i++)
{
CV_LOG_IF_VERBOSE(NULL, 0, i == 0 || i == 42, "Verbose message: " << i);
CV_LOG_IF_VERBOSE(NULL, 1, i == 0 || i == 42, "Verbose message: " << i);
CV_LOG_IF_DEBUG(NULL, i == 0 || i == 42, "Debug message: " << i);
CV_LOG_IF_INFO(NULL, i == 0 || i == 42, "Info message: " << i);
CV_LOG_IF_WARNING(NULL, i == 0 || i == 42, "Warning message: " << i);
CV_LOG_IF_ERROR(NULL, i == 0 || i == 42, "Error message: " << i);
CV_LOG_IF_FATAL(NULL, i == 0 || i == 42, "Fatal message: " << i);
}
}


TEST(Samples, findFile)
{
cv::utils::logging::LogLevel prev = cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_VERBOSE);
Expand Down
17 changes: 10 additions & 7 deletions modules/dnn/src/graph_simplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ int Subgraph::getInputNodeId(const Ptr<ImportGraphWrapper>& net,
const int numNodes = net->getNumNodes();
for (int i = 0; i < numNodes; ++i)
{
if (net->getNodeName(i) == name)
return i;
const int numOutputs = net->getNumOutputs(i);
for (int j = 0; j < numOutputs; j++)
{
if (net->getOutputName(i, j) == name)
return i;
}
}
CV_Error(Error::StsParseError, "Input node with name " + name + " not found");
}
Expand Down Expand Up @@ -111,12 +115,12 @@ bool Subgraph::match(const Ptr<ImportGraphWrapper>& net, int nodeId,
continue;
nodeId = getInputNodeId(net, node, j);
const Ptr<ImportNodeWrapper> inpNode = net->getNode(nodeId);
if (inpNode->getType() != "Const")
if (inpNode->getType() != "Const" && inpNode->getType() != "Constant")
{
nodesToMatch.push(nodeId);
targetNodes.push(inputNodes[j]);
}
else if (nodes[inputNodes[j]] != "Const")
else if (nodes[inputNodes[j]] != "Const" && nodes[inputNodes[j]] != "Constant")
return false;
}
matchedNodesIds.push_back(nodeToMatch);
Expand Down Expand Up @@ -190,15 +194,14 @@ void simplifySubgraphs(const Ptr<ImportGraphWrapper>& net,
{
int numNodes = net->getNumNodes();
std::vector<int> matchedNodesIds, targetNodesIds;
for (int i = 0; i < numNodes; ++i)
for (int j = 0; j < patterns.size(); ++j)
{
for (int j = 0; j < patterns.size(); ++j)
for (int i = 0; i < numNodes; ++i)
{
if (patterns[j]->match(net, i, matchedNodesIds, targetNodesIds))
{
patterns[j]->replace(net, matchedNodesIds, targetNodesIds);
numNodes -= matchedNodesIds.size() - 1; // #matchedNodes removed and one added.
break;
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion modules/dnn/src/graph_simplifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class ImportGraphWrapper

virtual int getNumNodes() const = 0;

virtual std::string getNodeName(int idx) const = 0;
virtual int getNumOutputs(int nodeId) const = 0;

virtual std::string getOutputName(int nodeId, int outId) const = 0;

virtual void removeNode(int idx) = 0;
};
Expand Down