From 7b3b249a7f2320f97e21e94e26a65f4b4ead0b6e Mon Sep 17 00:00:00 2001 From: shikeying <shikeying@163.com> Date: 星期六, 24 九月 2022 16:50:25 +0800 Subject: [PATCH] 视频相似度分析1 --- recommend-video/src/main/java/com/iplatform/recvideo/SimilarExecutor.java | 107 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 93 insertions(+), 14 deletions(-) diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/SimilarExecutor.java b/recommend-video/src/main/java/com/iplatform/recvideo/SimilarExecutor.java index 90d4868..1318e53 100644 --- a/recommend-video/src/main/java/com/iplatform/recvideo/SimilarExecutor.java +++ b/recommend-video/src/main/java/com/iplatform/recvideo/SimilarExecutor.java @@ -1,12 +1,15 @@ package com.iplatform.recvideo; import com.iplatform.model.po.Rc_video_t1; +import com.iplatform.recvideo.util.PythonInvokeUtils; +import com.iplatform.recvideo.util.TestUtils; import com.iplatform.recvideo.util.VideoFileUtils; import com.walker.infrastructure.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; +import java.util.ArrayList; import java.util.List; /** @@ -25,7 +28,9 @@ private String batchId = null; + // 褰撳墠鎵规瑕佸鐞嗙殑鍘熷瑙嗛闆嗗悎 private List<VideoFolderInfo> videoFolderInfoList = null; + private List<String> videoIdList = new ArrayList<>(); // 璁板綍褰撳墠鎵ц鍒�(璇ユ壒娆�)鍝釜瑙嗛鏂囦欢瀵瑰簲鐨勭鍑犱釜鍥剧墖 private int currentVideoFolderIndex = -1; @@ -33,15 +38,24 @@ // private VideoFolderInfo currentVideoFolderInfo = null; // private ImageInfo currentImageInfo = null; - // + // 鏄惁宸插畬鎴愯棰戝姞杞借皟鐢紝瀹屾垚鍚庢墠鑳芥绱㈢浉浼艰棰� private boolean pythonLoadVideoDone = false; + + private int topN = 40; + + // 濡傛灉娴嬭瘯妯″紡锛屾暟鎹槸鍋囩殑! + private boolean testMode = false; + + public int getTopN() { + return topN; + } /** * 鍒濆鍖栧璞¤皟鐢ㄤ竴娆� * @param videoDataFolder * @param batchId */ - public void startup(String videoDataFolder, String batchId){ + public void startup(String videoDataFolder, String batchId, int topN, boolean testMode){ if(StringUtils.isEmpty(videoDataFolder)){ throw new IllegalArgumentException("瑙嗛鏂囦欢澶规牴鐩綍蹇呴』璁剧疆!"); } @@ -50,17 +64,28 @@ } this.videoDataFolder = videoDataFolder; this.batchId = batchId; + this.topN = topN; + this.testMode = testMode; // this.videoFolderInfoList = VideoFileUtils.getBatchVideoFolderInfo(this.videoDataFolder, batchId); + } + + public void destroy(){ + if(this.videoFolderInfoList != null){ + this.videoFolderInfoList.clear(); + } + if(this.videoIdList != null){ + this.videoIdList.clear(); + } } /** * 鍦ㄦ瘡娆¤皟搴︽椂閽熷懆鏈熸墽琛屼竴娆°�備緥濡�: 10绉掍竴娆°��<p></p> * 娉ㄦ剰锛氳鏂规硶鑻辩‘淇濇瘡娆¤皟鐢ㄤ笉浼氶噸澶嶆暟鎹�� */ - public void execute(){ + public int execute() throws Exception{ if(!this.pythonLoadVideoDone){ logger.debug("褰撳墠 pythonLoadVideoDone = false, 闇�瑕佹煡璇㈡暟鎹簱鏄惁宸插姞杞借棰�"); - this.pythonLoadVideoDone = this.pythonLoadVideoDone(this.batchId, videoDataFolder + File.separator + batchId); + this.pythonLoadVideoDone = this.pythonLoadVideoDone(this.batchId, VideoFileUtils.combineBatchPath(videoDataFolder, batchId)); } // 1: 濡傛灉瑙嗛杩樻湭鍔犺浇锛屽垯鍏堝姞杞借棰� @@ -70,29 +95,42 @@ if(StringUtils.isNotEmpty(error)){ // 缁堟璋冪敤锛岀瓑寰呬笅娆¤皟搴︾户缁皾璇曟墽琛� logger.error("python璋冪敤鍔犺浇瑙嗛杩斿洖閿欒:" + error); - return; + return -1; } this.pythonLoadVideoDone = true; } catch (Exception ex){ logger.error("python璋冪敤鍔犺浇瑙嗛寮傚父:" + this.batchId, ex); - return; + return -1; } } // 2: 鍔犺浇瀹岃棰戯紝闇�瑕佹煡璇㈡瘡涓浘鐗囩浉浼煎害缁撴灉锛屽苟瀛樺偍鍒版暟鎹簱 // 杩欓噷娉ㄦ剰锛岀▼搴忓繀椤诲拰AI鏈嶅姟鍣ㄩ儴缃插湪涓�璧凤紝鏂逛究妫�绱㈣棰戝垎鏋愭枃浠跺す(鏈湴) if(this.videoFolderInfoList == null){ - this.videoFolderInfoList = VideoFileUtils.getBatchVideoFolderInfo(this.videoDataFolder, batchId); + if(testMode){ + this.videoFolderInfoList = TestUtils.getBatchVideoFolderInfo(this.videoDataFolder, batchId); + } else { + this.videoFolderInfoList = VideoFileUtils.getBatchVideoFolderInfo(this.videoDataFolder, batchId); + } } if(StringUtils.isEmptyList(this.videoFolderInfoList)){ logger.warn("瑙嗛鍒嗘瀽鏂囦欢澶瑰唴瀹逛负绌猴紝鏃犳硶缁х画鏌ヨ鐩镐技搴︾粨鏋�! videoFolderInfoList = null"); - return; + return -1; + } + for(VideoFolderInfo v : this.videoFolderInfoList){ + this.videoIdList.add(v.getVideoId()); } if(this.isSearchWriteDone()){ - logger.info("宸茬粡瀹屾垚鎵规鐩镐技缁撴灉鍐欏叆鏁版嵁搴擄紝涓嶅啀寰�涓嬪鐞嗐�俠atch = " + this.batchId); - return; + logger.info("宸茬粡瀹屾垚鎵规鐩镐技缁撴灉鍐欏叆鏁版嵁搴擄紝澶勭悊鏈�鍚庝竴姝�:鍐欏叆鐢ㄦ埛鎺ㄨ崘琛ㄦ暟鎹�俠atch = " + this.batchId); + try { + this.writeRcVideoUser(this.batchId, this.videoIdList); + // 杩斿洖1琛ㄧず鏁翠釜娴佺▼鎵ц瀹屾瘯銆� + return 1; + } catch (Exception ex){ + throw new Exception("writeRcVideoUser():" + ex.getMessage(), ex); + } } // 寮�濮嬫绱㈢浉浼煎害 @@ -100,6 +138,12 @@ this.currentVideoFolderIndex ++; } + try { + this.processOneSearchAndWrite(); + return 0; + } catch (Exception e) { + throw new Exception("processOneSearchAndWrite(): " + e.getMessage(), e); + } } private void processOneSearchAndWrite() throws Exception{ @@ -113,20 +157,34 @@ } ImageInfo imageInfo = currentVideoFolderInfo.getImageInfoList().get(this.currentImageIndex); - this.acquirePythonSearchSimilarOnce(imageInfo.getImagePath(), "30"); + List<Rc_video_t1> videoT1_list = this.acquirePythonSearchSimilarOnce(imageInfo.getVideoId() + , imageInfo.getImagePath(), String.valueOf(this.topN)); + if(!StringUtils.isEmptyList(videoT1_list)){ + try { + this.writeRcVideoT1(videoT1_list, PythonInvokeUtils.getFileNameWithoutSuffix(imageInfo.getImagePath(), Constants.IMAGE_SUFFIX)); + } catch (Exception ex){ + throw new Exception("writeRcVideoT1()鎵ц閿欒:" + ex.getMessage(), ex); + } + } + // 姣忎釜瑙嗛鐨勬渶鍚庝竴寮犲浘鐗� if((this.currentImageIndex + 1) >= currentVideoFolderInfo.getImageInfoSize()){ + try { + this.writeRcVideoT2(currentVideoFolderInfo); + } catch (Exception ex){ + throw new Exception("writeRcVideoT2()鎵ц閿欒:" + ex.getMessage(), ex); + } if((this.currentVideoFolderIndex + 1) < this.videoFolderInfoList.size()){ logger.debug("涓�涓棰戝浘鍍忛泦鍚堟绱㈠鐞嗗畬姣曪紝鍒囨崲鍒颁笅涓�涓紝currentImageIndex = " + this.currentImageIndex); this.currentVideoFolderIndex ++; this.currentImageIndex = -1; } else { - // + // 璁╂渶鍚庝竴涓浘鍍忛泦鍚堢储寮曞�艰秴杩囩晫闄愶紝琛ㄧず鏈�鍚庝竴涓棰戝凡澶勭悊瀹屾瘯銆� + this.currentImageIndex ++; logger.debug("鎵�鏈夎棰戝寘鍚殑鎵�鏈夊浘鍍忓鐞嗗畬姣曪紝currentVideoFolderIndex = " + this.currentVideoFolderIndex); } return; } - this.currentImageIndex ++; } @@ -167,5 +225,26 @@ * 璇锋眰AI鏈嶅姟锛屾绱㈢粰瀹氬浘鐗囩殑鐩镐技搴︾粨鏋滈泦鍚堛�� * @return */ - protected abstract List<Rc_video_t1> acquirePythonSearchSimilarOnce(String imagePath, String topN); + protected abstract List<Rc_video_t1> acquirePythonSearchSimilarOnce(String videoId + , String imagePath, String topN) throws Exception; + + /** + * 绗竴涓复鏃惰〃'rc_video_t1'锛屾瘡寮犲浘鍍忓寘鍚涓浉浼艰棰戣褰曘�� + * @param list + * @param srcImageId 鍘熷瑙嗛ID + */ + protected abstract void writeRcVideoT1(List<Rc_video_t1> list, String srcImageId); + + /** + * 鍒嗘瀽琛�'rc_video_t1'锛屽苟鎶婄粰瀹氳棰戠浉浼艰褰曞啓鍏ョ浜屼釜涓存椂琛�'rc_video_t2' + * @param videoFolderInfo + */ + protected abstract void writeRcVideoT2(VideoFolderInfo videoFolderInfo); + + /** + * 鍒嗘瀽缁欏畾鎵规鎵�鏈夎棰戠敤鎴锋帹鑽愮殑瑙嗛淇℃伅锛屽苟鍐欏叆琛�:'rc_video_user' + * @param batchId + * @param recVideoIdList 鎺ㄨ崘瑙嗛id闆嗗悎 + */ + protected abstract void writeRcVideoUser(String batchId, List<String> recVideoIdList); } -- Gitblit v1.9.1