深度学习、AI构图、智能裁图、显著性检测、美感质量评价
生活随笔
收集整理的這篇文章主要介紹了
深度学习、AI构图、智能裁图、显著性检测、美感质量评价
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
深度學(xué)習(xí)、AI構(gòu)圖、智能裁圖、顯著性檢測、美感質(zhì)量評價
基于美感數(shù)據(jù)集和改進(jìn)的Alexnet-SPP的AI構(gòu)圖智能裁圖
基于美感數(shù)據(jù)集和改進(jìn)的Alexnet-SPP的顯著性檢測
部分代碼下載地址:下載地址
實現(xiàn)思路和流程圖
1. 基于顯著性數(shù)據(jù)集,利用Alexnet-SPP回歸出圖像的顯著性區(qū)域;
2. 基于顯著性區(qū)域生成4x4或者5x5的候選框;
3. 利用美感質(zhì)量數(shù)據(jù)集訓(xùn)練度量學(xué)習(xí)Siamese Network,對顯著性候選框進(jìn)行打分。
4. 對打分后的候選框進(jìn)行排序,進(jìn)行智能裁圖。
效果展示:
測試代碼:
import tensorflow as tf
import numpy as np
import cv2
import itertoolstf.reset_default_graph()def gen_datalabel(filePath):f = open(filePath)lines = f.readlines()lenNum = len(lines)Num = 0imPath =[]imgs = []for line in lines:Num = Num + 1result = line.split(',')im = result[0]print imimPath.append(im)print (Num,'--',lenNum, im)img = cv2.imread(im)img = cv2.resize(img, (640, 480))imgs.append(img)return imPath, np.asarray(imgs, np.float32)def generate_box(x, y, z, w, img, imgPath):box_centerx = int((x + z) / 2.0)box_centery = int((y + w) / 2.0)ratiosx = [1.0, 1.05, 1.1, 1.2, 1.3, 1.5]ratiosy = [1.0, 1.05, 1.1, 1.2, 1.3, 1.5]# ratiosx = [0.9, 0.95, 1.0, 1.05, 1.1, 1.15, 1.2, 1.3, 1.5]# ratiosy = [0.9, 0.95, 1.0, 1.05, 1.1, 1.15, 1.2, 1.3, 1.5]bbox_result = []bbox_result.append(imgPath)print (imgPath)for ratiox, ratioy in itertools.product(ratiosx, ratiosy):boxw = int((z - x) * ratiox)boxh = int((w - y) * ratioy)gen_boxx = max(box_centerx - (boxw / 2), 0)gen_boxy = max(box_centery - (boxh / 2), 0)gen_boxz = min(box_centerx + (boxw / 2), img2.shape[1])gen_boxw = min(box_centery + (boxh / 2), img2.shape[0])bbox_result.append(gen_boxx)bbox_result.append(gen_boxy)bbox_result.append(gen_boxz)bbox_result.append(gen_boxw)print(gen_boxx, gen_boxy, gen_boxz, gen_boxw)cv2.rectangle(img, (gen_boxx, gen_boxy), (gen_boxz, gen_boxw), (0, 255, 0), 5)return img, bbox_resultfilePath = 'data_lab.txt'
imPath, data = gen_datalabel(filePath)
bbox_file = open('bbox_file_lab.txt', 'a')
W_image = 640
H_image = 480with tf.Session() as sess:saver = tf.train.import_meta_graph('./model/model.ckpt.meta')saver.restore(sess, tf.train.latest_checkpoint('./model/'))graph = tf.get_default_graph()x_input = graph.get_tensor_by_name("x_input:0")keep_prob = graph.get_tensor_by_name("Placeholder_1:0")#attention to modifyfeed_dict = {x_input: data, keep_prob: 0.5}logits = graph.get_tensor_by_name("logits_eval:0")cls_result = sess.run(logits, feed_dict)for i in range(len(imPath)):# result_path1 = './lab_data/' + (imPath[i].split('/'))[2]# result_path2 = './lab_crop/' + (imPath[i].split('/'))[2]result_path3 = './lab_candidate/' + (imPath[i].split('/'))[2]img2 = cv2.imread(imPath[i])retxx = float(img2.shape[1]) / W_imageretyy = float(img2.shape[0]) / H_image# cv2.rectangle(img2, ( max(int(retxx * cls_result[i][0]), 0), max(int(retyy * cls_result[i][1]), 0)),# ( min(int(retxx * cls_result[i][2]), img2.shape[1]), min(int(retyy * cls_result[i][3]), img2.shape[0])), (0, 0, 0), 5)#cv2.imwrite(result_path2, img2)xx, yy, ww, hh = int( max(retxx * cls_result[i][0], 0)), int( max(retyy * cls_result[i][1], 0)), int( min(retxx * cls_result[i][2], img2.shape[1])), int( min(retyy * cls_result[i][3], img2.shape[0]))img3, bbox_data= generate_box(xx, yy, ww, hh, img2, imPath[i])cv2.rectangle(img3, (xx, yy), (ww, hh),(0, 0, 0), 25)cv2.imwrite(result_path3, img3)for j in range(len(bbox_data)):bbox_file.write(str(bbox_data[j]) + ',')if j % 4 == 0:bbox_file.write('bbox' + str(j / 4) + ',')bbox_file.write('\n')bbox_file.close()
總結(jié)
以上是生活随笔為你收集整理的深度学习、AI构图、智能裁图、显著性检测、美感质量评价的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 除了成绩,93%的美国大学招生官最注重申
- 下一篇: 朱永新:教师的幸福感到底从何而来?