提交 f175a040 编写于 作者: A Alexander Alekhin

Merge pull request #11504 from alalek:check_flake8

...@@ -338,6 +338,7 @@ OCV_OPTION(CV_DISABLE_OPTIMIZATION "Disable explicit optimized code (dispatch ...@@ -338,6 +338,7 @@ OCV_OPTION(CV_DISABLE_OPTIMIZATION "Disable explicit optimized code (dispatch
OCV_OPTION(CV_TRACE "Enable OpenCV code trace" ON) OCV_OPTION(CV_TRACE "Enable OpenCV code trace" ON)
OCV_OPTION(ENABLE_PYLINT "Add target with Pylint checks" (${BUILD_DOCS} OR ${BUILD_EXAMPLES}) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) ) OCV_OPTION(ENABLE_PYLINT "Add target with Pylint checks" (${BUILD_DOCS} OR ${BUILD_EXAMPLES}) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
OCV_OPTION(ENABLE_FLAKE8 "Add target with Python flake8 checker" (${BUILD_DOCS} OR ${BUILD_EXAMPLES}) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
if(ENABLE_IMPL_COLLECTION) if(ENABLE_IMPL_COLLECTION)
add_definitions(-DCV_COLLECT_IMPL_DATA) add_definitions(-DCV_COLLECT_IMPL_DATA)
...@@ -645,9 +646,22 @@ if(BUILD_JAVA) ...@@ -645,9 +646,22 @@ if(BUILD_JAVA)
endif() endif()
endif() endif()
if(ENABLE_PYLINT) if(ENABLE_PYLINT AND PYTHON_DEFAULT_AVAILABLE)
include(cmake/OpenCVPylint.cmake) include(cmake/OpenCVPylint.cmake)
endif() endif()
if(ENABLE_FLAKE8 AND PYTHON_DEFAULT_AVAILABLE)
find_package(Flake8 QUIET)
if(NOT FLAKE8_FOUND OR NOT FLAKE8_EXECUTABLE)
include("${CMAKE_CURRENT_LIST_DIR}/cmake/FindFlake8.cmake")
endif()
if(FLAKE8_FOUND)
add_custom_target(check_flake8
COMMAND "${FLAKE8_EXECUTABLE}" . --count --select=E9,E901,E999,F821,F822,F823 --show-source --statistics --exclude='.git,__pycache__,*.config.py,svgfig.py'
WORKING_DIRECTORY "${OpenCV_SOURCE_DIR}"
COMMENT "Running flake8"
)
endif()
endif()
if(ANDROID AND ANDROID_EXECUTABLE AND ANT_EXECUTABLE AND (ANT_VERSION VERSION_GREATER 1.7) AND (ANDROID_TOOLS_Pkg_Revision GREATER 13)) if(ANDROID AND ANDROID_EXECUTABLE AND ANT_EXECUTABLE AND (ANT_VERSION VERSION_GREATER 1.7) AND (ANDROID_TOOLS_Pkg_Revision GREATER 13))
...@@ -1449,6 +1463,9 @@ status(" Python (for build):" PYTHON_DEFAULT_AVAILABLE THEN "${PYTHON_DEFAULT_ ...@@ -1449,6 +1463,9 @@ status(" Python (for build):" PYTHON_DEFAULT_AVAILABLE THEN "${PYTHON_DEFAULT_
if(PYLINT_FOUND AND PYLINT_EXECUTABLE) if(PYLINT_FOUND AND PYLINT_EXECUTABLE)
status(" Pylint:" PYLINT_FOUND THEN "${PYLINT_EXECUTABLE} (ver: ${PYLINT_VERSION}, checks: ${PYLINT_TOTAL_TARGETS})" ELSE NO) status(" Pylint:" PYLINT_FOUND THEN "${PYLINT_EXECUTABLE} (ver: ${PYLINT_VERSION}, checks: ${PYLINT_TOTAL_TARGETS})" ELSE NO)
endif() endif()
if(FLAKE8_FOUND AND FLAKE8_EXECUTABLE)
status(" Flake8:" FLAKE8_FOUND THEN "${FLAKE8_EXECUTABLE} (ver: ${FLAKE8_VERSION})" ELSE NO)
endif()
# ========================== java ========================== # ========================== java ==========================
if(BUILD_JAVA OR BUILD_opencv_java) if(BUILD_JAVA OR BUILD_opencv_java)
......
# - Find Flake8
# Find the Flake8 executable and extract the version number
#
# OUTPUT Variables
#
# FLAKE8_FOUND
# True if the flake8 package was found
# FLAKE8_EXECUTABLE
# The flake8 executable location
# FLAKE8_VERSION
# A string denoting the version of flake8 that has been found
find_host_program(FLAKE8_EXECUTABLE flake8 PATHS /usr/bin)
if(FLAKE8_EXECUTABLE)
execute_process(COMMAND ${FLAKE8_EXECUTABLE} --version OUTPUT_VARIABLE FLAKE8_VERSION_RAW ERROR_QUIET)
if(FLAKE8_VERSION_RAW MATCHES "^([0-9\\.]+[0-9])")
set(FLAKE8_VERSION "${CMAKE_MATCH_1}")
else()
set(FLAKE8_VERSION "unknown")
endif()
endif()
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Flake8 DEFAULT_MSG FLAKE8_EXECUTABLE)
mark_as_advanced(FLAKE8_EXECUTABLE FLAKE8_VERSION)
from __future__ import print_function from __future__ import print_function
import sys
import argparse import argparse
import cv2 as cv import cv2 as cv
import tensorflow as tf import tensorflow as tf
import numpy as np import numpy as np
import struct import struct
if sys.version_info > (3,):
long = int
from tensorflow.python.tools import optimize_for_inference_lib from tensorflow.python.tools import optimize_for_inference_lib
from tensorflow.tools.graph_transforms import TransformGraph from tensorflow.tools.graph_transforms import TransformGraph
from tensorflow.core.framework.node_def_pb2 import NodeDef from tensorflow.core.framework.node_def_pb2 import NodeDef
......
from __future__ import print_function
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
import numpy as np import numpy as np
import sys import sys
...@@ -156,7 +157,7 @@ class DnnCaffeModel(Framework): ...@@ -156,7 +157,7 @@ class DnnCaffeModel(Framework):
class ClsAccEvaluation: class ClsAccEvaluation:
log = file log = sys.stdout
img_classes = {} img_classes = {}
batch_size = 0 batch_size = 0
...@@ -198,26 +199,26 @@ class ClsAccEvaluation: ...@@ -198,26 +199,26 @@ class ClsAccEvaluation:
fw_accuracy.append(100 * correct_answers[i] / float(samples_handled)) fw_accuracy.append(100 * correct_answers[i] / float(samples_handled))
frameworks_out.append(out) frameworks_out.append(out)
inference_time[i] += end - start inference_time[i] += end - start
print >> self.log, samples_handled, 'Accuracy for', frameworks[i].get_name() + ':', fw_accuracy[i] print(samples_handled, 'Accuracy for', frameworks[i].get_name() + ':', fw_accuracy[i], file=self.log)
print >> self.log, "Inference time, ms ", \ print("Inference time, ms ", \
frameworks[i].get_name(), inference_time[i] / samples_handled * 1000 frameworks[i].get_name(), inference_time[i] / samples_handled * 1000, file=self.log)
for i in range(1, len(frameworks)): for i in range(1, len(frameworks)):
log_str = frameworks[0].get_name() + " vs " + frameworks[i].get_name() + ':' log_str = frameworks[0].get_name() + " vs " + frameworks[i].get_name() + ':'
diff = np.abs(frameworks_out[0] - frameworks_out[i]) diff = np.abs(frameworks_out[0] - frameworks_out[i])
l1_diff = np.sum(diff) / diff.size l1_diff = np.sum(diff) / diff.size
print >> self.log, samples_handled, "L1 difference", log_str, l1_diff print(samples_handled, "L1 difference", log_str, l1_diff, file=self.log)
blobs_l1_diff[i] += l1_diff blobs_l1_diff[i] += l1_diff
blobs_l1_diff_count[i] += 1 blobs_l1_diff_count[i] += 1
if np.max(diff) > blobs_l_inf_diff[i]: if np.max(diff) > blobs_l_inf_diff[i]:
blobs_l_inf_diff[i] = np.max(diff) blobs_l_inf_diff[i] = np.max(diff)
print >> self.log, samples_handled, "L_INF difference", log_str, blobs_l_inf_diff[i] print(samples_handled, "L_INF difference", log_str, blobs_l_inf_diff[i], file=self.log)
self.log.flush() self.log.flush()
for i in range(1, len(blobs_l1_diff)): for i in range(1, len(blobs_l1_diff)):
log_str = frameworks[0].get_name() + " vs " + frameworks[i].get_name() + ':' log_str = frameworks[0].get_name() + " vs " + frameworks[i].get_name() + ':'
print >> self.log, 'Final l1 diff', log_str, blobs_l1_diff[i] / blobs_l1_diff_count[i] print('Final l1 diff', log_str, blobs_l1_diff[i] / blobs_l1_diff_count[i], file=self.log)
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
......
from __future__ import print_function
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
import numpy as np import numpy as np
import sys import sys
...@@ -145,7 +146,7 @@ class PASCALDataFetch(DatasetImageFetch): ...@@ -145,7 +146,7 @@ class PASCALDataFetch(DatasetImageFetch):
class SemSegmEvaluation: class SemSegmEvaluation:
log = file log = sys.stdout
def __init__(self, log_path,): def __init__(self, log_path,):
self.log = open(log_path, 'w') self.log = open(log_path, 'w')
...@@ -174,28 +175,28 @@ class SemSegmEvaluation: ...@@ -174,28 +175,28 @@ class SemSegmEvaluation:
pix_acc, mean_acc, miou = get_metrics(conf_mats[i]) pix_acc, mean_acc, miou = get_metrics(conf_mats[i])
name = frameworks[i].get_name() name = frameworks[i].get_name()
print >> self.log, samples_handled, 'Pixel accuracy, %s:' % name, 100 * pix_acc print(samples_handled, 'Pixel accuracy, %s:' % name, 100 * pix_acc, file=self.log)
print >> self.log, samples_handled, 'Mean accuracy, %s:' % name, 100 * mean_acc print(samples_handled, 'Mean accuracy, %s:' % name, 100 * mean_acc, file=self.log)
print >> self.log, samples_handled, 'Mean IOU, %s:' % name, 100 * miou print(samples_handled, 'Mean IOU, %s:' % name, 100 * miou, file=self.log)
print >> self.log, "Inference time, ms ", \ print("Inference time, ms ", \
frameworks[i].get_name(), inference_time[i] / samples_handled * 1000 frameworks[i].get_name(), inference_time[i] / samples_handled * 1000, file=self.log)
for i in range(1, len(frameworks)): for i in range(1, len(frameworks)):
log_str = frameworks[0].get_name() + " vs " + frameworks[i].get_name() + ':' log_str = frameworks[0].get_name() + " vs " + frameworks[i].get_name() + ':'
diff = np.abs(frameworks_out[0] - frameworks_out[i]) diff = np.abs(frameworks_out[0] - frameworks_out[i])
l1_diff = np.sum(diff) / diff.size l1_diff = np.sum(diff) / diff.size
print >> self.log, samples_handled, "L1 difference", log_str, l1_diff print(samples_handled, "L1 difference", log_str, l1_diff, file=self.log)
blobs_l1_diff[i] += l1_diff blobs_l1_diff[i] += l1_diff
blobs_l1_diff_count[i] += 1 blobs_l1_diff_count[i] += 1
if np.max(diff) > blobs_l_inf_diff[i]: if np.max(diff) > blobs_l_inf_diff[i]:
blobs_l_inf_diff[i] = np.max(diff) blobs_l_inf_diff[i] = np.max(diff)
print >> self.log, samples_handled, "L_INF difference", log_str, blobs_l_inf_diff[i] print(samples_handled, "L_INF difference", log_str, blobs_l_inf_diff[i], file=self.log)
self.log.flush() self.log.flush()
for i in range(1, len(blobs_l1_diff)): for i in range(1, len(blobs_l1_diff)):
log_str = frameworks[0].get_name() + " vs " + frameworks[i].get_name() + ':' log_str = frameworks[0].get_name() + " vs " + frameworks[i].get_name() + ':'
print >> self.log, 'Final l1 diff', log_str, blobs_l1_diff[i] / blobs_l1_diff_count[i] print('Final l1 diff', log_str, blobs_l1_diff[i] / blobs_l1_diff_count[i], file=self.log)
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
......
...@@ -206,6 +206,8 @@ class table(object): ...@@ -206,6 +206,8 @@ class table(object):
cell.width = len(max(cell.text, key = lambda line: len(line))) cell.width = len(max(cell.text, key = lambda line: len(line)))
def reformatTextValue(self, value): def reformatTextValue(self, value):
if sys.version_info > (3,): # PY3 fix
unicode = str
if isinstance(value, str): if isinstance(value, str):
vstr = value vstr = value
elif isinstance(value, unicode): elif isinstance(value, unicode):
......
...@@ -7,6 +7,10 @@ import os.path ...@@ -7,6 +7,10 @@ import os.path
import sys import sys
from xml.dom.minidom import parse from xml.dom.minidom import parse
if sys.version_info > (3,):
long = int
def cmp(a, b): return (a>b)-(a<b)
class TestInfo(object): class TestInfo(object):
def __init__(self, xmlnode): def __init__(self, xmlnode):
......
...@@ -335,6 +335,7 @@ if __name__ == "__main__": ...@@ -335,6 +335,7 @@ if __name__ == "__main__":
print(cfg.strip()) print(cfg.strip())
print('=' * 80) print('=' * 80)
ABIs = None # make flake8 happy
exec(compile(cfg, cpath, 'exec')) exec(compile(cfg, cpath, 'exec'))
log.info("Android NDK path: %s", os.environ["ANDROID_NDK"]) log.info("Android NDK path: %s", os.environ["ANDROID_NDK"])
......
...@@ -79,7 +79,7 @@ if __name__ == '__main__': ...@@ -79,7 +79,7 @@ if __name__ == '__main__':
img = cv.imread(fn, 0) img = cv.imread(fn, 0)
if img is None: if img is None:
print('Failed to load fn1:', fn1) print('Failed to load file:', fn)
sys.exit(1) sys.exit(1)
img = np.float32(img)/255.0 img = np.float32(img)/255.0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册