利用scipy包计算表格线的峰值,还原表格得到表格结构

1. 利用scipy包计算表格线的峰值

import cv2
import numpy as np
from scipy.signal import find_peaks, peak_widthsdef get_lines_from_image(img_bin, axis, kernel_len_div = 20, kernel_len = None, iters = 3):""":param img_bin: opencv img:param axis: 0 对应竖直, 1对应水平线:param kernel_len_div: 相对于边长的几分之几:param kernel_len: 直接给定和长度,如果这个长度不为0, 上述例子失效:return:"""DEBUG = True# Defining a kernel lengthif kernel_len is not None:assert kernel_len > 0kernel_length = kernel_lenelse:kernel_length = max(np.array(img_bin).shape[axis] // kernel_len_div, 1)if axis == 0:# A verticle kernel of (1 X kernel_length), which will detect all the verticle lines from the image.verticle_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1, kernel_length))# Morphological operation to detect verticle lines from an imageimg_temp1 = cv2.erode(img_bin, verticle_kernel, iterations=iters)verticle_lines_img = cv2.dilate(img_temp1, verticle_kernel, iterations=iters)if DEBUG:cv2.imwrite("verticle_lines.jpg", verticle_lines_img)return verticle_lines_imgelse:# A horizontal kernel of (kernel_length X 1), which will help to detect all the horizontal line from the image.hori_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (kernel_length, 1))# Morphological operation to detect horizontal lines from an imageimg_temp2 = cv2.erode(img_bin, hori_kernel, iterations=iters)horizontal_lines_img = cv2.dilate(img_temp2, hori_kernel, iterations=iters)if DEBUG:cv2.imwrite("horizontal_lines.jpg", horizontal_lines_img)return horizontal_lines_imgdef line_img_add(verticle_lines_img, horizontal_lines_img):# 把检测出来的横线和竖线相加alpha = 0.5beta = 1.0 - alphaimg_final_bin = cv2.addWeighted(verticle_lines_img, alpha, horizontal_lines_img, beta, 0.0)return img_final_bindef project(np_arr, axis):# 水平或垂直投影, 0竖直,1水平return np.count_nonzero(np_arr == 0, axis=axis)def get_grid_coordinate(img_bin, prominence_ratio = 0.3, height_ratio=None, distance=None, DEBUG=0):"""计算格点水平(x)和竖直(y)坐标和线宽:param img_bin: 白底黑线:return:"""#参数# prominence_ratio 峰值的突出程度, 相对于表格长宽h, w = img_bin.shape# print("size",h,w)x_prj = project(img_bin, 0)y_prj = project(img_bin, 1)# 检测峰值# high_ratio = 0.1 # todo 这也是一个参数height_x = height_y = Noneif height_ratio is not None:height_x = height_ratio * hheight_y = height_ratio * w# x_peaks, _ = find_peaks(x_prj, height=high_ratio*h, distance = max(1,w/20), prominence=(h*prominence_ratio, None))# y_peaks, _ = find_peaks(y_prj, height=high_ratio*w, distance = max(1,w/50), prominence=(w*prominence_ratio, None))print('height_x,height_y:', height_x, height_y)x_peaks, _ = find_peaks(x_prj, height=height_x, distance=distance,  prominence=(h * prominence_ratio, None))y_peaks, _ = find_peaks(y_prj, height=height_y, distance=distance, prominence=(w * prominence_ratio, None))x_peaks = list(x_peaks)y_peaks = list(y_peaks)DEBUG =Trueif DEBUG:#plotimport matplotlib.pyplot as pltimg = img_binplt.subplot(211)plt.title("x")print('range(x_prj.shape[0]):',range(x_prj.shape[0]))plt.plot(range(x_prj.shape[0]), x_prj)plt.plot(x_peaks, x_prj[x_peaks], "x")plt.subplot(212)plt.title("y")plt.plot(range(y_prj.shape[0]), y_prj)plt.plot(y_peaks, y_prj[y_peaks], "x")plt.show()if len(x_peaks) == 0: # 如果没检测到峰值, 把检测框边界峰值x_peaks = [0, w]print("x_peaks is None !!!!!!!")if len(y_peaks) == 0:y_peaks = [0, h]print("y_peaks is None !!!!!!!")# 计算线宽, 假设线宽一定, 横有m根线, 竖有n根线, 表格高为h, 宽为w, 线宽为x# n_nonzero = m*w*x + n*h*x - m*n*x^2# n_nonzero 约等于 m*w*x + n*h*xh,w = img_bin.shapem,n = len(y_peaks), len(x_peaks)line_width = np.count_nonzero(img_bin == 0) / (m*w + n*h)line_width = round(line_width) + 1return x_peaks, y_peaks, line_widthif __name__ == '__main__':path= './test_page_debug_out_debug/table_crop_fix_rm_char.jpg'img = cv2.imread(path)img_bin = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)verticle_lines_img = get_lines_from_image(img_bin, 0, kernel_len_div=40)horizontal_lines_img = get_lines_from_image(img_bin, 1, kernel_len_div=40)# 表格线提取img_final_bin_lines = line_img_add(verticle_lines_img, horizontal_lines_img)cv2.imwrite('./img_final_bin_lines.jpg',img_final_bin_lines)kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))# 膨胀并二值化img_final_bin_lines = cv2.erode(~img_final_bin_lines, kernel, iterations=2)(thresh, img_final_bin_lines) = cv2.threshold(img_final_bin_lines, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)cv2.imwrite('./img_final_bin_lines_fix.jpg', img_final_bin_lines)# 根据表格线计算格点坐标 -----------------------------------x_grids, y_grids, line_w = get_grid_coordinate(img_final_bin_lines)

输入:

提取竖直线:

提取水平线:

水平线与竖直线峰值查找:

二. 还原表格结构

import cv2
from PIL import Image
import numpy as np
import os
import os.path as osp
from scipy.signal import find_peaks, peak_widthsdebug = Truedef get_lines_from_image(img_bin, axis, kernel_len_div=20, kernel_len=None, iters=3):""":param img_bin: opencv img:param axis: 0 对应竖直, 1对应水平线:param kernel_len_div: 相对于边长的几分之几:param kernel_len: 直接给定和长度,如果这个长度不为0, 上述例子失效:return:"""DEBUG = 0# Defining a kernel lengthif kernel_len is not None:assert kernel_len > 0kernel_length = kernel_lenelse:kernel_length = max(np.array(img_bin).shape[axis] // kernel_len_div, 1)if axis == 0:# A verticle kernel of (1 X kernel_length), which will detect all the verticle lines from the image.verticle_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1, kernel_length))# Morphological operation to detect verticle lines from an imageimg_temp1 = cv2.erode(img_bin, verticle_kernel, iterations=iters)verticle_lines_img = cv2.dilate(img_temp1, verticle_kernel, iterations=iters)if DEBUG:cv2.imwrite("verticle_lines.jpg", verticle_lines_img)return verticle_lines_imgelse:# A horizontal kernel of (kernel_length X 1), which will help to detect all the horizontal line from the image.hori_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (kernel_length, 1))# Morphological operation to detect horizontal lines from an imageimg_temp2 = cv2.erode(img_bin, hori_kernel, iterations=iters)horizontal_lines_img = cv2.dilate(img_temp2, hori_kernel, iterations=iters)if DEBUG:cv2.imwrite("horizontal_lines.jpg", horizontal_lines_img)return horizontal_lines_imgdef line_img_add(verticle_lines_img, horizontal_lines_img):# Weighting parameters, this will decide the quantity of an image to be added to make a new image.alpha = 0.5beta = 1.0 - alpha# This function helps to add two image with specific weight parameter to get a third image as summation of two image.img_final_bin = cv2.addWeighted(verticle_lines_img, alpha, horizontal_lines_img, beta, 0.0)return img_final_bindef project(np_arr, axis):# 水平或垂直投影, 0竖直,1水平return np.count_nonzero(np_arr == 0, axis=axis)def get_grid_coordinate(img_bin, prominence_ratio=0.3, height_ratio=None, distance=None):"""计算格点水平(x)和竖直(y)坐标和线宽:param img_bin: 白底黑线:return:"""# 参数# prominence_ratio 峰值的突出程度, 相对于表格长宽h, w = img_bin.shapeDEBUG = Falseif DEBUG:cv2.imwrite('table_crop.jpg', img_bin)# print("size",h,w)x_prj = project(img_bin, 0)y_prj = project(img_bin, 1)# 检测峰值# high_ratio = 0.1 # todo 这也是一个参数height_x = height_y = Noneif height_ratio is not None:height_x = height_ratio * hheight_y = height_ratio * w# x_peaks, _ = find_peaks(x_prj, height=high_ratio*h, distance = max(1,w/20), prominence=(h*prominence_ratio, None))# y_peaks, _ = find_peaks(y_prj, height=high_ratio*w, distance = max(1,w/50), prominence=(w*prominence_ratio, None))x_peaks, _ = find_peaks(x_prj, height=height_x, distance=distance, prominence=(h * prominence_ratio, None))y_peaks, _ = find_peaks(y_prj, height=height_y, distance=distance, prominence=(w * prominence_ratio, None))if DEBUG:# plotimport matplotlib.pyplot as pltimg = img_binplt.subplot(211)plt.title("x")plt.plot(range(x_prj.shape[0]), x_prj)plt.plot(x_peaks, x_prj[x_peaks], "x")plt.subplot(212)plt.title("y")plt.plot(range(y_prj.shape[0]), y_prj)plt.plot(y_peaks, y_prj[y_peaks], "x")plt.show()# cv2.waitKey(0)if len(x_peaks) == 0:  # 如果没检测到峰值, 把检测框边界峰值x_peaks = [0, w]# print("x_peaks is None !!!!!!!")if len(y_peaks) == 0:y_peaks = [0, h]# print("y_peaks is None !!!!!!!")# 计算线宽, 假设线宽一定, 横有m根线, 竖有n根线, 表格高为h, 宽为w, 线宽为x# n_nonzero = m*w*x + n*h*x - m*n*x^2#  n_nonzero 约等于 m*w*x + n*h*xh, w = img_bin.shapem, n = len(y_peaks), len(x_peaks)line_width = np.count_nonzero(img_bin == 0) / (m * w + n * h)line_width = max(round(line_width), 1)return list(x_peaks), list(y_peaks), line_width
def check_line_exist(img_bin, pt1, pt2, width, threshold=0.5, DEBUG=0):# 剪切图片以加速x1 = min(pt1[0], pt2[0])x2 = max(pt1[0], pt2[0])y1 = min(pt1[1], pt2[1])y2 = max(pt1[1], pt2[1])h, w = img_bin.shaped = width * 2x1 = max(0, x1 - d)y1 = max(0, y1 - d)x2 = min(w-1, x2 + d)y2 = min(h-1, y2 + d)img_bin = img_bin[y1: y2, x1: x2].copy()pt1 = (pt1[0] - x1, pt1[1] - y1)pt2 = (pt2[0] - x1, pt2[1] - y1)if DEBUG:cv2.imwrite('./img_bin_after_crop.jpg', img_bin)# print("now check", pt1, pt2)line_mask = np.zeros_like(img_bin)cv2.line(line_mask, pt1, pt2, color=(255, 255, 255), thickness=width)mask_cnt = np.count_nonzero(line_mask)img_bin_tmp = ~img_bin.copy()kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))img_bin_tmp = cv2.dilate(img_bin_tmp, kernel, iterations=1)img_after_mask = cv2.bitwise_and(line_mask, img_bin_tmp)and_cnt = np.count_nonzero(img_after_mask)if DEBUG:cv2.imwrite("./line_mask.jpg", line_mask)cv2.imwrite('./img_after_mask.jpg', img_after_mask)cv2.imwrite("./img_bin_tmp.jpg", img_bin_tmp)# print('check_line_exist', (and_cnt / mask_cnt))return (and_cnt / mask_cnt) > thresholddef get_table_structure(img_final_bin_lines, x_grids, y_grids, line_w):# 推断表格结构# 判断每条边是否存在, 不存在在改边两边区域相连DEBUG = 0n_x = len(x_grids)n_y = len(y_grids)if DEBUG:print("n_x, n_y", n_x, n_y)cell_id_mark = np.full((n_y - 1, n_x - 1), -1, dtype=int)  # 给每个cell一个id,id相同代表联通cell_id_sets = [set() for _ in range(n_x * n_y)]  # 记录每个id包含哪些cellid = 0# def f(row, col):#     # 单元格坐标转序号#     return n_x*row + col## def f_revers(id):#     # 序号转单元格坐标#     return (id//n_x, id%n_x)# 检查竖直线if len(x_grids) > 2:for x_id, x in enumerate(x_grids[1:-1]):x_id += 1  # 因为是从1开始for y_id, y in enumerate(y_grids[:-1]):if not check_line_exist(img_final_bin_lines, (x, y), (x, y_grids[y_id + 1]), width=line_w,threshold=0.5, DEBUG=False):# if DEBUG:print("没有发现竖直线:x_id,y_id", x_id, y_id)left_id = cell_id_mark[y_id, x_id - 1]# print('==left_id:', left_id)if left_id == -1:cell_id_mark[y_id, x_id - 1] = idcell_id_mark[y_id, x_id] = idcell_id_sets[id].add((y_id, x_id - 1))cell_id_sets[id].add((y_id, x_id))id += 1else:cell_id_mark[y_id, x_id] = left_idcell_id_sets[left_id].add((y_id, x_id))print('==cell_id_mark:', cell_id_mark)# assert 1 == 0# print('cell_id_sets', cell_id_sets)# 检查水平线if len(y_grids) > 2:for y_id, y in enumerate(y_grids[1:-1]):y_id += 1for x_id, x in enumerate(x_grids[:-1]):# print(cell_id_mark)if not check_line_exist(img_final_bin_lines, (x_grids[x_id + 1], y), (x, y), width=line_w,threshold=0.5, DEBUG=False):# if DEBUG:print("======没有发现水平线,x_id, y_id", x_id, y_id)up_id = cell_id_mark[y_id - 1, x_id]down_id = cell_id_mark[y_id, x_id]# print('===up_id:', up_id)# print('===down_id:', down_id)if up_id != -1:if down_id != -1:if up_id != down_id:  # 合并同一区域的id# print('cell_id_sets[up_id]',cell_id_sets[up_id])# print('cell_id_sets[down_id]', cell_id_sets[down_id])cell_id_mark[y_id, x_id] = up_idcell_id_sets[up_id] |= cell_id_sets[down_id]cell_id_sets[down_id].clear()# print('cell_id_sets[up_id]',cell_id_sets[up_id])else:cell_id_mark[y_id, x_id] = up_idcell_id_sets[up_id].add((y_id, x_id))else:cell_id_mark[y_id - 1, x_id] = idcell_id_mark[y_id, x_id] = idcell_id_sets[id].add((y_id - 1, x_id))cell_id_sets[id].add((y_id, x_id))id += 1print('==cell_id_mark:', cell_id_mark)# assert 1 == 0print('==x_grids:', x_grids)print('==y_grids:', y_grids)print('==cell_id_mark:', cell_id_mark)print('==cell_id_sets:', cell_id_sets)# 填补其他没id的单元格依次加1for x_id, x in enumerate(x_grids[:-1]):for y_id, y in enumerate(y_grids[:-1]):if cell_id_mark[y_id, x_id] == -1:cell_id_mark[y_id, x_id] = idcell_id_sets[id].add((y_id, x_id))id += 1print('==cell_id_mark:', cell_id_mark)print('==cell_id_sets:', cell_id_sets)print('==id:', id)# assert 1 == 0# print('after check ver',cell_id_mark)# print(cell_id_sets)# 输出rst = []for id in range(id):if len(cell_id_sets[id]) == 0:continueif len(cell_id_sets[id]) == 1:cell = {}cell_row, cell_col = list(cell_id_sets[id])[0]cell["id"] = idcell["row_start"] = cell_row  # 结构坐标cell["col_start"] = cell_colcell["row_end"] = cell_row + 1cell["col_end"] = cell_col + 1cell["x1"] = x_grids[cell_col]  # 绝对坐标cell["y1"] = y_grids[cell_row]cell["x2"] = x_grids[cell_col + 1]cell["y2"] = y_grids[cell_row + 1]cell["crnn"] = []  # 后续使用cell["text"] = ""  # 后续使用rst.append(cell)else:id_min = sorted(cell_id_sets[id])[0]id_max = sorted(cell_id_sets[id])[-1]cell = {}cell_row_min, cell_col_min = id_mincell_row_max, cell_col_max = id_maxcell["id"] = idcell["row_start"] = cell_row_min  # 结构坐标cell["col_start"] = cell_col_mincell["row_end"] = cell_row_max + 1cell["col_end"] = cell_col_max + 1cell["x1"] = x_grids[cell_col_min]  # 绝对坐标cell["y1"] = y_grids[cell_row_min]cell["x2"] = x_grids[cell_col_max + 1]cell["y2"] = y_grids[cell_row_max + 1]cell["crnn"] = []  # 后续使用cell["text"] = ""  # 后续使用rst.append(cell)return cell_id_mark, rstdef box_extraction(cv_img):"""提取有框线表格结构, 返回list [[row_start,col_start,row_end,col_end],[...]]:param img_path::param result_path::return:"""if len(cv_img.shape) == 3:cv_img = cv2.cvtColor(cv_img, cv2.COLOR_BGR2GRAY)# 二值化# (thresh, img_bin) = cv2.threshold(cv_img, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)  # Thresholding the imageimg_bin = cv2.adaptiveThreshold(cv_img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, \cv2.THRESH_BINARY, 11, 2)img_bin = 255 - img_bin  # Invert the image# 二次消除小轮廓image, contours, hierarchy = cv2.findContours(img_bin, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)mask = np.ones(image.shape[:2], dtype="uint8") * 255th_w = img_bin.shape[1] / 30th_h = img_bin.shape[0] / 30for c in contours:x, y, w, h = cv2.boundingRect(c)  # 第一遍根据长宽删选if w < th_w and h < th_h:cv2.drawContours(mask, [c], -1, 0, -1)img_bin = cv2.bitwise_and(img_bin, img_bin, mask=mask)if debug:cv2.imwrite('./img_bin_no_noise.jpg', img_bin)kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (3, 3))img_bin = cv2.dilate(img_bin, kernel, iterations=1)image, contours, hierarchy = cv2.findContours(img_bin, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)mask = np.ones(image.shape[:2], dtype="uint8") * 255th_w = img_bin.shape[1] / 5th_h = img_bin.shape[0] / 5for c in contours:if cv2.contourArea(c) < th_w * th_h:cv2.drawContours(mask, [c], -1, 0, -1)img_bin = cv2.bitwise_and(img_bin, img_bin, mask=mask)if debug:cv2.imwrite("img_remove_noise2.jpg", img_bin)verticle_lines_img = get_lines_from_image(img_bin, 0, kernel_len_div=40)horizontal_lines_img = get_lines_from_image(img_bin, 1, kernel_len_div=40)# 表格线提取img_final_bin_lines = line_img_add(verticle_lines_img, horizontal_lines_img)# 膨胀并二值化# A kernel of (3 X 3) ones.kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))img_final_bin_lines = cv2.erode(~img_final_bin_lines, kernel, iterations=2)(thresh, img_final_bin_lines) = cv2.threshold(img_final_bin_lines, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)if debug:cv2.imwrite("img_final_bin_lines.jpg", img_final_bin_lines)# 根据表格线计算格点坐标x_grids, y_grids, line_w = get_grid_coordinate(img_final_bin_lines)print('===x_grids, y_grids, line_w:', x_grids, y_grids, line_w)cell_id_mark, rst = get_table_structure(img_final_bin_lines, x_grids, y_grids, line_w)return x_grids, y_grids, cell_id_mark, rstdef debug_single_img():# img_path = './table_crop.jpg'img_path = './table_crop2.png'img = cv2.imread(img_path, 0)  # Read the imagex_grids, y_grids, cell_id_mark, rst = box_extraction(img)print('==x_grids:', x_grids)print('==y_grids:', y_grids)print('==cell_id_mark:', cell_id_mark)print('==rst:', rst)if __name__ == '__main__':debug_single_img()

在将rst接入这篇博客就还原出相应的excel啦.

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/493205.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

原子智库 | 刘伟:人工智能快追上人类思维?答案可能让你失望

来源&#xff1a;原子智库摘要&#xff1a;2018年12月15日&#xff0c;原子智库主办的“改革的规则与创新——2018光华腾讯经济年会暨风云演讲”在北京大学举办北京邮电大学人机交互与认知工程实验室主任刘伟发表演讲。演讲的话题是未来工业化发展、智能化发展。刘伟在演讲中指…

利用xlwt写excel并进行单元格的合并

1.写入行列值 import xlwt # 创建一个workbook 设置编码 workbook xlwt.Workbook(encodingutf-8) # 创建一个worksheet worksheet workbook.add_sheet(My Worksheet)# 写入excel # 参数对应 行, 列, 值 worksheet.write(1, 0, label this is test)# 保存 workbook.save(Exc…

为了边缘计算,亚马逊、谷歌、微软已正面交锋!

来源&#xff1a;全球物联网观察摘要&#xff1a;so&#xff0c;你真的了解边缘计算吗&#xff1f;边缘计算的前世今生云计算自2005年提出之后&#xff0c;就开始逐步地改变我们的生活、学习、工作的方式。云计算使得公司能够在自己的物理硬件之外&#xff0c;通过远程服务器网…

每日一小练——二项式系数加法解

上得厅堂&#xff0c;下得厨房&#xff0c;写得代码&#xff0c;翻得围墙&#xff0c;欢迎来到睿不可挡的每日一小练&#xff01; 题目&#xff1a;二项式系数加法解 内容&#xff1a;请编写一个程序&#xff0c;仅仅用加法&#xff0c;求出n中取r个组合系数C(n,r)&#xff0c;…

华为、苹果、高通,谁在领跑?全面解读清华AI芯片报告

来源&#xff1a;智东西摘要&#xff1a;本文全面讲解人工智能芯片&#xff0c;系统梳理人工智能芯片的发展现状及趋势。2010 年以来&#xff0c;由于大数据产业的发展&#xff0c;数据量呈现爆炸性增长态势&#xff0c;而传统的计算架构又无法支撑深度学习的大规模并行计算需求…

SSD300网络结构(pytorch)+多尺度训练与测试

一.SSD300 1.如图是预测框的相应feature map 这里smin是0.2&#xff0c;表示最底层的scale是0.2&#xff1b;smax是0.9&#xff0c;表示最高层的scale是0.9,m代表产生尺度预测的feature map个数。 其中anchor的长宽关系&#xff0c;s就是上图中的scale,a就是上图中的anchor …

01-08-02【Nhibernate (版本3.3.1.4000) 出入江湖】二级缓存:NHibernate自带的HashtableProvider...

第一步骤&#xff1a;hibernate.cfg.xml文件补上如下配置&#xff1a; <?xml version"1.0" encoding"utf-8"?> <!-- This template was written to work with NHibernate.Test. Copy the template to your NHibernate.Test project folder and…

2018, 自动驾驶异常艰难的一年

编译&#xff1a;张玺 &#xff0c;编辑&#xff1a;宇多田摘要&#xff1a;虽然文章几乎聚焦于美国硅谷的技术公司&#xff0c;但这并不意味着作者提出的种种问题不存在于中国的技术公司身上。有意思的是&#xff0c;作者批评了各大公司此前疯狂立 flag&#xff0c;却最后纷纷…

目标检测矩形框与polygon数据增加--裁剪,拓展,旋转

1.裁剪 import torch from torchvision import transforms import cv2 import numpy as np import types from numpy import random class RandomSampleCrop(object):"""CropArguments:img (Image): the image being input during trainingboxes (Tensor): th…

医生们说,AI不会取代我们!

来源&#xff1a;IEEE电气电子工程师学会每次人工智能在医疗任务中与医生进行竞争&#xff08;对此我们已经报道过很多次&#xff09;时&#xff0c;一个问题不可避免地浮出水面&#xff1a;人工智能会取代医生吗&#xff1f;如果你与AI 专家或硅谷投资者交谈&#xff0c;答案往…

ubuntu安装python3.5+pycharm+anaconda+opencv+docker+nvidia-docker+tensorflow+pytorch+Cmake3.8

一&#xff0c;切换python版本为3.5 装好ubuntu&#xff0c;python版本是2.7的 我自己安装并更改打开为python3.5 sudo apt-get install python3.5 设置优先级和默认环境&#xff1a; sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100 su…

学界 | 量化深度强化学习算法的泛化能力

来源&#xff1a;AI 科技评论OpenAI 近期发布了一个新的训练环境 CoinRun&#xff0c;它提供了一个度量智能体将其学习经验活学活用到新情况的能力指标&#xff0c;而且还可以解决一项长期存在于强化学习中的疑难问题——即使是广受赞誉的强化算法在训练过程中也总是没有运用监…

《科学》评出2018年度十大科学突破事件

来源&#xff1a;科学大院《科学》杂志每年会评出在即将过去的一年里最为重要的十大科学突破&#xff08;Science Breakthrough&#xff09;。今年&#xff0c;夺得年度突破桂冠的是“单细胞水平细胞谱系追踪技术”&#xff0c;帮助破获多起悬案的法医系谱技术、#MeToo 运动等也…

递归理解以及时间复杂度计算

一.复杂度分析&#xff1a; 可以理解为递归的深度就是空间复杂度&#xff0c;时间复杂度就是O(T*depth),其中&#xff34;是每个递归函数的时间复杂度&#xff0c;depth是递归深度&#xff0e; #空间复杂度O(1) def sum1_(n):res 0for i in range(n1):resireturn res#递归 空…

性价比高出英特尔45%,亚马逊的云服务器芯片如何做到?| 解读

来源&#xff1a;TheNextPlatform编译&#xff1a;机器之能 张玺摘要&#xff1a;到目前为止&#xff0c;亚马逊和其他大型云运营商几乎全部使用英特尔的 Xeon 芯片。虽然在服务器芯片市场&#xff0c;英特尔市场占有率非常高&#xff0c;但亚马逊正使用折扣策略来赢得客户。亚…

GIOU loss+DIOU loss+CIOU loss

一.IOU 1.GIOU解决没有交集的框,IOU为0,其损失函数导数为0,无法优化的问题。 图1 GIOU,IOU,l2范数差异 a)可看出 l2值一样,IOU值是不一样的,说明L1,L2这些Loss用于回归任务时&#xff0c;不能等价于最后用于评测检测的IoU. b)可看出当框有包含关系,GIOU就退化为IOU 其是找…

《科学》十大年度科学突破反映的新动向

来源&#xff1a;新华网摘要&#xff1a;从测定分子结构到宇宙探索&#xff0c;从发现远古动物到揭示细胞的秘密&#xff0c;美国权威学术刊物《科学》杂志评选的2018年十大科学突破&#xff0c;在时间和空间尺度上拓宽着人类认知的边界&#xff0c;也反映了近年来科学发展的三…

ctpn论文阅读与代码

代码地址: https://github.com/zonghaofan/ctpn_torch 1.通用的目标检测是封闭的,而文字是封闭且连续 2. 构造一系列宽度相等的小文本,回归中心y坐标和高度 3. 对于边界回归x坐标,在进一次修正 4.整个模型就是backbone提取特征,将每个像素点的相邻3*3像素拉成行向量,利用空间…

yum配置与使用

yum配置与使用(很详细) yum的配置一般有两种方式&#xff0c;一种是直接配置/etc目录下的yum.conf文件&#xff0c;另外一种是在/etc/yum.repos.d目录下增加.repo文件。一、yum的配置文件$ cat /etc/yum.conf [main]cachedir/var/cache/yum #yum下载的RPM包的缓存目录k…

新技术不断涌现,下一代云计算的突破口在哪里?

来源&#xff1a;日知录技术社区这是一个IT技术飞速发展的时代&#xff0c;在硬件基础设施的不断升级以及虚拟化网络等技术的日益成熟下&#xff0c;云厂商也正面临着各种新技术带来的巨大挑战。从数据中心的基础建设到云平台的系统构建再到产品底层的技术改革&#xff0c;该如…