python: better Python 3 support

pull/11504/head
Alexander Alekhin 7 years ago
parent df02fe0615
commit 78f205ffa5
  1. 4
      modules/dnn/misc/quantize_face_detector.py
  2. 15
      modules/dnn/test/imagenet_cls_test_alexnet.py
  3. 19
      modules/dnn/test/pascal_semsegm_test_fcn.py
  4. 2
      modules/ts/misc/table_formatter.py
  5. 4
      modules/ts/misc/testlog_parser.py
  6. 1
      platforms/android/build_sdk.py
  7. 2
      samples/python/deconvolution.py

@ -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…
Cancel
Save