CHINESE-OCR icon indicating copy to clipboard operation
CHINESE-OCR copied to clipboard

bbox.py无法过编译 windows10系统

Open 13120678025 opened this issue 4 years ago • 12 comments

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 . . .

13120678025 avatar Nov 28 '19 07:11 13120678025

同样的问题

yipenglinoe avatar Jan 29 '20 12:01 yipenglinoe

编译 windows10系统 我已经解决,可加群755860371 共同研究

QQ2737499951 avatar May 19 '20 13:05 QQ2737499951

你好,请问一下是如何解决的?

LycsHub avatar Jul 31 '20 09:07 LycsHub

楼上那个群,还要付费加群。。晕死。。

lmw0320 avatar Aug 25 '20 02:08 lmw0320

我把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`

lmw0320 avatar Aug 25 '20 08:08 lmw0320

同理,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`

lmw0320 avatar Aug 25 '20 08:08 lmw0320

我也遇到了同样的问题

QiTianDaShengDaShi avatar Jan 01 '21 17:01 QiTianDaShengDaShi

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

QiTianDaShengDaShi avatar Jan 01 '21 17:01 QiTianDaShengDaShi

只是不知道这样更改有没错: `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`

老哥,有缩进版本吗

QiTianDaShengDaShi avatar Jan 01 '21 17:01 QiTianDaShengDaShi

我把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`

老哥,已经成功,感谢,上面那个让加群还收费的人真是让人可笑,笑掉大牙。

QiTianDaShengDaShi avatar Jan 02 '21 16:01 QiTianDaShengDaShi

我把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`

老哥太感谢了!这就是开源精神!

1Dreamer666 avatar Sep 30 '23 07:09 1Dreamer666

这是来自AAAAAAAAAAAAAA  

QQ2737499951 avatar Sep 30 '23 07:09 QQ2737499951