mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 14:36:36 +08:00
Merge pull request #11504 from alalek:check_flake8
This commit is contained in:
commit
f175a04014
@ -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(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)
|
||||
add_definitions(-DCV_COLLECT_IMPL_DATA)
|
||||
@ -645,9 +646,22 @@ if(BUILD_JAVA)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(ENABLE_PYLINT)
|
||||
if(ENABLE_PYLINT AND PYTHON_DEFAULT_AVAILABLE)
|
||||
include(cmake/OpenCVPylint.cmake)
|
||||
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))
|
||||
@ -1449,6 +1463,9 @@ status(" Python (for build):" PYTHON_DEFAULT_AVAILABLE THEN "${PYTHON_DEFAULT_
|
||||
if(PYLINT_FOUND AND PYLINT_EXECUTABLE)
|
||||
status(" Pylint:" PYLINT_FOUND THEN "${PYLINT_EXECUTABLE} (ver: ${PYLINT_VERSION}, checks: ${PYLINT_TOTAL_TARGETS})" ELSE NO)
|
||||
endif()
|
||||
if(FLAKE8_FOUND AND FLAKE8_EXECUTABLE)
|
||||
status(" Flake8:" FLAKE8_FOUND THEN "${FLAKE8_EXECUTABLE} (ver: ${FLAKE8_VERSION})" ELSE NO)
|
||||
endif()
|
||||
|
||||
# ========================== java ==========================
|
||||
if(BUILD_JAVA OR BUILD_opencv_java)
|
||||
|
27
cmake/FindFlake8.cmake
Normal file
27
cmake/FindFlake8.cmake
Normal file
@ -0,0 +1,27 @@
|
||||
# - 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)
|
@ -1,10 +1,14 @@
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
import argparse
|
||||
import cv2 as cv
|
||||
import tensorflow as tf
|
||||
import numpy as np
|
||||
import struct
|
||||
|
||||
if sys.version_info > (3,):
|
||||
long = int
|
||||
|
||||
from tensorflow.python.tools import optimize_for_inference_lib
|
||||
from tensorflow.tools.graph_transforms import TransformGraph
|
||||
from tensorflow.core.framework.node_def_pb2 import NodeDef
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
from abc import ABCMeta, abstractmethod
|
||||
import numpy as np
|
||||
import sys
|
||||
@ -156,7 +157,7 @@ class DnnCaffeModel(Framework):
|
||||
|
||||
|
||||
class ClsAccEvaluation:
|
||||
log = file
|
||||
log = sys.stdout
|
||||
img_classes = {}
|
||||
batch_size = 0
|
||||
|
||||
@ -198,26 +199,26 @@ class ClsAccEvaluation:
|
||||
fw_accuracy.append(100 * correct_answers[i] / float(samples_handled))
|
||||
frameworks_out.append(out)
|
||||
inference_time[i] += end - start
|
||||
print >> self.log, samples_handled, 'Accuracy for', frameworks[i].get_name() + ':', fw_accuracy[i]
|
||||
print >> self.log, "Inference time, ms ", \
|
||||
frameworks[i].get_name(), inference_time[i] / samples_handled * 1000
|
||||
print(samples_handled, 'Accuracy for', frameworks[i].get_name() + ':', fw_accuracy[i], file=self.log)
|
||||
print("Inference time, ms ", \
|
||||
frameworks[i].get_name(), inference_time[i] / samples_handled * 1000, file=self.log)
|
||||
|
||||
for i in range(1, len(frameworks)):
|
||||
log_str = frameworks[0].get_name() + " vs " + frameworks[i].get_name() + ':'
|
||||
diff = np.abs(frameworks_out[0] - frameworks_out[i])
|
||||
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_count[i] += 1
|
||||
if np.max(diff) > blobs_l_inf_diff[i]:
|
||||
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()
|
||||
|
||||
for i in range(1, len(blobs_l1_diff)):
|
||||
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__":
|
||||
parser = argparse.ArgumentParser()
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
from abc import ABCMeta, abstractmethod
|
||||
import numpy as np
|
||||
import sys
|
||||
@ -145,7 +146,7 @@ class PASCALDataFetch(DatasetImageFetch):
|
||||
|
||||
|
||||
class SemSegmEvaluation:
|
||||
log = file
|
||||
log = sys.stdout
|
||||
|
||||
def __init__(self, log_path,):
|
||||
self.log = open(log_path, 'w')
|
||||
@ -174,28 +175,28 @@ class SemSegmEvaluation:
|
||||
pix_acc, mean_acc, miou = get_metrics(conf_mats[i])
|
||||
|
||||
name = frameworks[i].get_name()
|
||||
print >> self.log, samples_handled, 'Pixel accuracy, %s:' % name, 100 * pix_acc
|
||||
print >> self.log, samples_handled, 'Mean accuracy, %s:' % name, 100 * mean_acc
|
||||
print >> self.log, samples_handled, 'Mean IOU, %s:' % name, 100 * miou
|
||||
print >> self.log, "Inference time, ms ", \
|
||||
frameworks[i].get_name(), inference_time[i] / samples_handled * 1000
|
||||
print(samples_handled, 'Pixel accuracy, %s:' % name, 100 * pix_acc, file=self.log)
|
||||
print(samples_handled, 'Mean accuracy, %s:' % name, 100 * mean_acc, file=self.log)
|
||||
print(samples_handled, 'Mean IOU, %s:' % name, 100 * miou, file=self.log)
|
||||
print("Inference time, ms ", \
|
||||
frameworks[i].get_name(), inference_time[i] / samples_handled * 1000, file=self.log)
|
||||
|
||||
for i in range(1, len(frameworks)):
|
||||
log_str = frameworks[0].get_name() + " vs " + frameworks[i].get_name() + ':'
|
||||
diff = np.abs(frameworks_out[0] - frameworks_out[i])
|
||||
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_count[i] += 1
|
||||
if np.max(diff) > blobs_l_inf_diff[i]:
|
||||
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()
|
||||
|
||||
for i in range(1, len(blobs_l1_diff)):
|
||||
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__":
|
||||
parser = argparse.ArgumentParser()
|
||||
|
@ -206,6 +206,8 @@ class table(object):
|
||||
cell.width = len(max(cell.text, key = lambda line: len(line)))
|
||||
|
||||
def reformatTextValue(self, value):
|
||||
if sys.version_info > (3,): # PY3 fix
|
||||
unicode = str
|
||||
if isinstance(value, str):
|
||||
vstr = value
|
||||
elif isinstance(value, unicode):
|
||||
|
@ -7,6 +7,10 @@ import os.path
|
||||
import sys
|
||||
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):
|
||||
|
||||
def __init__(self, xmlnode):
|
||||
|
@ -335,6 +335,7 @@ if __name__ == "__main__":
|
||||
print(cfg.strip())
|
||||
print('=' * 80)
|
||||
|
||||
ABIs = None # make flake8 happy
|
||||
exec(compile(cfg, cpath, 'exec'))
|
||||
|
||||
log.info("Android NDK path: %s", os.environ["ANDROID_NDK"])
|
||||
|
@ -79,7 +79,7 @@ if __name__ == '__main__':
|
||||
|
||||
img = cv.imread(fn, 0)
|
||||
if img is None:
|
||||
print('Failed to load fn1:', fn1)
|
||||
print('Failed to load file:', fn)
|
||||
sys.exit(1)
|
||||
|
||||
img = np.float32(img)/255.0
|
||||
|
Loading…
Reference in New Issue
Block a user