Open 13120678025 opened 4 years ago
同样的问题
编译 windows10系统 我已经解决,可加群755860371 共同研究
你好,请问一下是如何解决的?
楼上那个群,还要付费加群。。晕死。。
boxes: (N, 4) ndarray of float
query_boxes: (K, 4) ndarray of float
Returns
-------
overlaps: (N, K) ndarray of overlap between boxes and query_boxes
"""
N = boxes.shape[0]
K = query_boxes.shape[0]
overlaps = np.zeros((N, K), dtype=np.float32)
for k in range(K):
box_area = (
(query_boxes[k, 2] - query_boxes[k, 0] + 1) *
(query_boxes[k, 3] - query_boxes[k, 1] + 1)
)
for n in range(N):
iw = (
min(boxes[n, 2], query_boxes[k, 2]) -
max(boxes[n, 0], query_boxes[k, 0]) + 1
)
if iw > 0:
ih = (
min(boxes[n, 3], query_boxes[k, 3]) -
max(boxes[n, 1], query_boxes[k, 1]) + 1
)
if ih > 0:
ua = float(
(boxes[n, 2] - boxes[n, 0] + 1) *
(boxes[n, 3] - boxes[n, 1] + 1) +
box_area - iw * ih
)
overlaps[n, k] = iw * ih / ua
return overlaps
Parameters
----------
boxes: (N, 4) ndarray of float
query_boxes: (K, 4) ndarray of float
Returns
-------
overlaps: (N, K) ndarray of intersec between boxes and query_boxes
"""
N = boxes.shape[0]
K = query_boxes.shape[0]
intersec = np.zeros((N, K), dtype=np.float32)
for k in range(K):
box_area = (
(query_boxes[k, 2] - query_boxes[k, 0] + 1) *
(query_boxes[k, 3] - query_boxes[k, 1] + 1)
)
for n in range(N):
iw = (
min(boxes[n, 2], query_boxes[k, 2]) -
max(boxes[n, 0], query_boxes[k, 0]) + 1
)
if iw > 0:
ih = (
min(boxes[n, 3], query_boxes[k, 3]) -
max(boxes[n, 1], query_boxes[k, 1]) + 1
)
if ih > 0:
intersec[n, k] = iw * ih / box_area
return intersec`
同理,cpython_nms.pyx文件也被我修改了下,修改后的完整内容如下: `import numpy as np def max(a, b): return a if a >= b else b
def min(a, b): return a if a <= b else b
def nms(dets, thresh): x1 = dets[:, 0] y1 = dets[:, 1] x2 = dets[:, 2] y2 = dets[:, 3] scores = dets[:, 4] areas = (x2 - x1 + 1) (y2 - y1 + 1) order = scores.argsort()[::-1] ndets = dets.shape[0] suppressed = np.zeros((ndets), dtype=np.int) keep = [] for _i in range(ndets): i = order[_i] if suppressed[i] == 1: continue keep.append(i) ix1 = x1[i] iy1 = y1[i] ix2 = x2[i] iy2 = y2[i] iarea = areas[i] for _j in range(_i + 1, ndets): j = order[_j] if suppressed[j] == 1: continue xx1 = max(ix1, x1[j]) yy1 = max(iy1, y1[j]) xx2 = min(ix2, x2[j]) yy2 = min(iy2, y2[j]) w = max(0.0, xx2 - xx1 + 1) h = max(0.0, yy2 - yy1 + 1) inter = w h ovr = inter / (iarea + areas[j] - inter) if ovr >= thresh: suppressed[j] = 1 return keep
def nms_new(dets, thresh): x1 = dets[:, 0] y1 = dets[:, 1] x2 = dets[:, 2] y2 = dets[:, 3] scores = dets[:, 4] areas = (x2 - x1 + 1) (y2 - y1 + 1) order = scores.argsort()[::-1] ndets = dets.shape[0] suppressed = np.zeros((ndets), dtype=np.int) keep = [] for _i in range(ndets): i = order[_i] if suppressed[i] == 1: continue keep.append(i) ix1 = x1[i] iy1 = y1[i] ix2 = x2[i] iy2 = y2[i] iarea = areas[i] for _j in range(_i + 1, ndets): j = order[_j] if suppressed[j] == 1: continue xx1 = max(ix1, x1[j]) yy1 = max(iy1, y1[j]) xx2 = min(ix2, x2[j]) yy2 = min(iy2, y2[j]) w = max(0.0, xx2 - xx1 + 1) h = max(0.0, yy2 - yy1 + 1) inter = w h ovr = inter / (iarea + areas[j] - inter) ovr1 = inter / iarea ovr2 = inter / areas[j] if ovr >= thresh or ovr1 > 0.95 or ovr2 > 0.95: suppressed[j] = 1 return keep`
我也遇到了同样的问题
File "E:\python_project\1229_OCR_detection\1229_OCR_detection_V110_Classify_CTPN_CRNN\CHINESE_OCR_master\ctpn\lib\utils\bbox.py", line 9 cimport numpy as np ^ SyntaxError: invalid syntax
只是不知道这样更改有没错: `import numpy as np def bbox_overlaps(boxes,query_boxes): “”“ 参数
框:(N,4)浮点数 ndquery_boxes:(K,4)浮点数ndarray 返回
重叠:(N,K)框间的重叠数ndarray和query_boxes “”” N = boxes.shape [0] K = query_boxes.shape [0] 重叠= np.zeros((N,K),D型细胞= np.float32) 对于k在范围(K): box_area =( (query_boxes [k,2]-query_boxes [k,0] + 1) (query_boxes [k,3]-query_boxes [k,1] + 1) ) 对于范围(N)中的n: iw =( min(boxes [n,2],query_boxes [k,2])- max(boxes [n,0],query_boxes [k,0])+ 1 ) 如果iw> 0: ih =( min(boxes [n, 3],query_boxes [k,3])- max(boxes [n,1],query_boxes [k,1])+ 1 ) 如果ih> 0: ua = float( (boxes [n,2] -box [n ,0] + 1) (boxes [n,3] -boxs [n,1] +1)+ box_area-iw ih ) 重叠[n,k] = iw ih / ua 返回重叠
def bbox_intersections(boxes,query_boxes): “”“ 对于每个查询框,计算框所覆盖的相交率
参数
框:(N,4)浮点数 ndquery_boxes的ndarray:(K,4)浮点数ndarray的 返回
重叠:(N,K)框和query_boxes之间的相交的ndarray “”“ N = box.shape [0] K = query_boxes。 shape [0] intersec = np.zeros((N,K),dtype = np.float32) 对于范围(K)中的k: box_area =( (query_boxes [k,2]-query_boxes [k,0] + 1) (query_boxes [K,3] - query_boxes [K,1] + 1) ) 在范围(N N): IW =( min(boxes [n,2],query_boxes [k,2])- max(boxes [n,0],query_boxes [k,0])+ 1 ) 如果iw> 0: ih =( min(boxes [n, 3],query_boxes [k,3])- max(boxes [n,1],query_boxes [k,1])+ 1 ) 如果ih> 0: intersec [n,k] = iw ih / box_area 返回intersec`
老哥,有缩进版本吗
我把bbox.pyx的内容调整了下,另存为bbox.py文件,就可以调用了。。只是不知道这样更改有没错: `import numpy as np def bbox_overlaps(boxes,query_boxes): """ Parameters
boxes: (N, 4) ndarray of float query_boxes: (K, 4) ndarray of float Returns
overlaps: (N, K) ndarray of overlap between boxes and query_boxes """ N = boxes.shape[0] K = query_boxes.shape[0] overlaps = np.zeros((N, K), dtype=np.float32) for k in range(K): box_area = ( (query_boxes[k, 2] - query_boxes[k, 0] + 1) (query_boxes[k, 3] - query_boxes[k, 1] + 1) ) for n in range(N): iw = ( min(boxes[n, 2], query_boxes[k, 2]) - max(boxes[n, 0], query_boxes[k, 0]) + 1 ) if iw > 0: ih = ( min(boxes[n, 3], query_boxes[k, 3]) - max(boxes[n, 1], query_boxes[k, 1]) + 1 ) if ih > 0: ua = float( (boxes[n, 2] - boxes[n, 0] + 1) (boxes[n, 3] - boxes[n, 1] + 1) + box_area - iw ih ) overlaps[n, k] = iw ih / ua return overlaps
def bbox_intersections(boxes, query_boxes): """ For each query box compute the intersection ratio covered by boxes
Parameters
boxes: (N, 4) ndarray of float query_boxes: (K, 4) ndarray of float Returns
overlaps: (N, K) ndarray of intersec between boxes and query_boxes """ N = boxes.shape[0] K = query_boxes.shape[0] intersec = np.zeros((N, K), dtype=np.float32) for k in range(K): box_area = ( (query_boxes[k, 2] - query_boxes[k, 0] + 1) (query_boxes[k, 3] - query_boxes[k, 1] + 1) ) for n in range(N): iw = ( min(boxes[n, 2], query_boxes[k, 2]) - max(boxes[n, 0], query_boxes[k, 0]) + 1 ) if iw > 0: ih = ( min(boxes[n, 3], query_boxes[k, 3]) - max(boxes[n, 1], query_boxes[k, 1]) + 1 ) if ih > 0: intersec[n, k] = iw ih / box_area return intersec`
老哥,已经成功,感谢,上面那个让加群还收费的人真是让人可笑,笑掉大牙。
我把bbox.pyx的内容调整了下,另存为bbox.py文件,就可以调用了。。只是不知道这样更改有没错: `import numpy as np def bbox_overlaps(boxes,query_boxes): """ Parameters ---------- boxes: (N, 4) ndarray of float query_boxes: (K, 4) ndarray of float Returns ------- overlaps: (N, K) ndarray of overlap between boxes and query_boxes """ N = boxes.shape[0] K = query_boxes.shape[0] overlaps = np.zeros((N, K), dtype=np.float32) for k in range(K): box_area = ( (query_boxes[k, 2] - query_boxes[k, 0] + 1) (query_boxes[k, 3] - query_boxes[k, 1] + 1) ) for n in range(N): iw = ( min(boxes[n, 2], query_boxes[k, 2]) - max(boxes[n, 0], query_boxes[k, 0]) + 1 ) if iw > 0: ih = ( min(boxes[n, 3], query_boxes[k, 3]) - max(boxes[n, 1], query_boxes[k, 1]) + 1 ) if ih > 0: ua = float( (boxes[n, 2] - boxes[n, 0] + 1) (boxes[n, 3] - boxes[n, 1] + 1) + box_area - iw ih ) overlaps[n, k] = iw ih / ua return overlaps
def bbox_intersections(boxes, query_boxes): """ For each query box compute the intersection ratio covered by boxes ---------- Parameters ---------- boxes: (N, 4) ndarray of float query_boxes: (K, 4) ndarray of float Returns ------- overlaps: (N, K) ndarray of intersec between boxes and query_boxes """ N = boxes.shape[0] K = query_boxes.shape[0] intersec = np.zeros((N, K), dtype=np.float32) for k in range(K): box_area = ( (query_boxes[k, 2] - query_boxes[k, 0] + 1) (query_boxes[k, 3] - query_boxes[k, 1] + 1) ) for n in range(N): iw = ( min(boxes[n, 2], query_boxes[k, 2]) - max(boxes[n, 0], query_boxes[k, 0]) + 1 ) if iw > 0: ih = ( min(boxes[n, 3], query_boxes[k, 3]) - max(boxes[n, 1], query_boxes[k, 1]) + 1 ) if ih > 0: intersec[n, k] = iw ih / box_area return intersec`
老哥太感谢了!这就是开源精神!
这是来自AAAAAAAAAAAAAA
Using TensorFlow backend. Traceback (most recent call last): File "C:\Users\WuDongLin\Desktop\图片对比\OCR_DeepLearning\demo.py", line 8, in
import model
File "C:\Users\WuDongLin\Desktop\图片对比\OCR_DeepLearning\model.py", line 15, in
from ctpn.text_detect import text_detect
File "C:\Users\WuDongLin\Desktop\图片对比\OCR_DeepLearning\ctpn\text_detect.py", line 3, in
from .ctpn.detectors import TextDetector
File "C:\Users\WuDongLin\Desktop\图片对比\OCR_DeepLearning\ctpn\ctpn\detectors.py", line 10, in
from ..lib.fast_rcnn.nms_wrapper import nms
File "C:\Users\WuDongLin\Desktop\图片对比\OCR_DeepLearning\ctpn\lib__init.py", line 1, in
from . import fast_rcnn
File "C:\Users\WuDongLin\Desktop\图片对比\OCR_DeepLearning\ctpn\lib\fast_rcnn__init__.py", line 2, in
from . import nms_wrapper
File "C:\Users\WuDongLin\Desktop\图片对比\OCR_DeepLearning\ctpn\lib\fast_rcnn\nms_wrapper.py", line 2, in
from ..utils.cython_nms import nms as cython_nms
File "C:\Users\WuDongLin\Desktop\图片对比\OCR_DeepLearning\ctpn\lib\utils\ init__.py", line 1, in
from . import bbox
File "C:\Users\WuDongLin\Desktop\图片对比\OCR_DeepLearning\ctpn\lib\utils\bbox.py", line 9
cimport numpy as np
^
SyntaxError: invalid syntax
Press any key to continue . . .