经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 大数据/云/AI » 人工智能基础 » 查看文章
[darknet]查看错误结果 sight of wrong
来源:cnblogs  作者:aimhabo  时间:2019/3/1 9:02:21  对本文有异议
  1. import os
  2. import numpy
  3. import cv2
  4. bad_label_file = open("bad_valid.list",'r')
  5. names = []
  6. for line in open('data/coco.names','r'):
  7. names.append(line.strip('\n'))
  8. classes = len(names)
  9. colors = []
  10. for i in range(80):
  11. #color = [random.uniform(0, 255),random.uniform(0, 255),random.uniform(0, 255)]
  12. color = [(i)*255/classes,(classes-i)*255/classes,(classes+i)*128/classes]
  13. colors.append(color)
  14. lines = []
  15. for line in bad_label_file:
  16. lines.append(line)
  17. mount = len(lines)
  18. oper=0
  19. i=0
  20. #for i in range(mount):
  21. while(i<mount):
  22. i+=oper
  23. words = lines[i].split(':')
  24. imagepath = words[0]
  25. #print('reading "{}: No. {}"'.format(path,indexes))
  26. print('{}\\{}'.format(mount,i))
  27. src = cv2.imread(imagepath)
  28. #cv2.imshow("src",src)
  29. h,w = src.shape[:2]
  30. labelpath = imagepath.split('-')[0]+'-labels/'+os.path.basename(imagepath).split('.')[0]+'.txt'
  31. try:
  32. labelfile = open(labelpath,'r')
  33. labels = []
  34. for line in labelfile:
  35. #print('get label {}'.format(line))
  36. labels.append(line)
  37. for label in labels:
  38. ti,tx,ty,tw,th = map(float,label.split(' ')[:5])
  39. #print('get label {} {} {} {} {}'.format(ti,tx,ty,tw,th))
  40. x0=w*(tx-tw/2)
  41. y0=h*(ty-th/2)
  42. x1=w*(tx+tw/2)
  43. y1=h*(ty+th/2)
  44. w0=w*tw
  45. h0=h*th
  46. ti,x0,y0,x1,y1,w0,h0 = map(int,[ti,x0,y0,x1,y1,w0,h0])
  47. #print('<({},{}),({},{})>,'.format(x0,y0,x1,y1))
  48. cv2.rectangle(src,(x0,y0),(x1,y1),colors[ti],2)
  49. y0+=15
  50. #cv2.putText(src,str(ti)+' '+names[ti],(x0+1,y0+1),cv2.FONT_HERSHEY_COMPLEX,0.5,colors[ti][::-1],1)
  51. #cv2.putText(src,str(ti)+' '+names[ti],(x0-1,y0-1),cv2.FONT_HERSHEY_COMPLEX,0.5,colors[ti][::-1],1)
  52. cv2.putText(src,str(ti)+' '+names[ti],(x0,y0),cv2.FONT_HERSHEY_COMPLEX,0.5,colors[ti],1)
  53. except :
  54. print('guess what? ERROR!(show_bad_valid.py::67)')
  55. words = words[1].strip('\n')
  56. probs = words.split(' ')[2:]
  57. #print(words)
  58. #print(probs)
  59. if len(probs) > 0:
  60. for prob in probs:
  61. values = prob.strip('<').strip('>').split(',')
  62. print(values)
  63. ti,tx,ty,tw,th = map(float,values[2:])
  64. x0=w*(tx-tw/2)
  65. y0=h*(ty-th/2)
  66. x1=w*(tx+tw/2)
  67. y1=h*(ty+th/2)
  68. ti,x0,y0,x1,y1 = map(int,[ti,x0,y0,x1,y1])
  69. y1-=10
  70. cv2.rectangle(src,(x0,y0),(x1,y1),colors[ti][::-1],1)
  71. cv2.putText(src,str(ti)+' '+names[ti],(x0,y1),cv2.FONT_HERSHEY_COMPLEX,0.5,colors[ti],1)
  72. cv2.imshow("image",src)
  73. key = cv2.waitKey(0)
  74. '''
  75. A 65
  76. a 97
  77. D 68
  78. d 100
  79. S 83
  80. s 115
  81. '''
  82. if key == 97:
  83. if i>0:
  84. oper=-1
  85. elif key == 100:
  86. if i<len(lines):
  87. oper=1
  88. elif key == 115:
  89. oper=0
  90. cv2.imwrite('workingspace.jpg',src)
  91. else:
  92. break
  93. bad_label_file.close()

 

原文链接:http://www.cnblogs.com/aimhabo/p/10449229.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号