当前位置: 首页 > news >正文

南京网站排名深圳竞价托管

南京网站排名,深圳竞价托管,有网站地图的网站,顺义网站建设yolov8先训练生成best.pt文件,用这个生成的模型进行视频的测试 因为本来用的代码生成的测试视频打不开,格式应该是损坏了,或者部分帧没有正常保存吧。 修改了一下代码,现状可以正常打开生成的视频了。 1、训练代码train.py im…

yolov8先训练生成best.pt文件,用这个生成的模型进行视频的测试

因为本来用的代码生成的测试视频打不开,格式应该是损坏了,或者部分帧没有正常保存吧。

修改了一下代码,现状可以正常打开生成的视频了。

1、训练代码train.py

import os# os.environ["CUDA_VISIBLE_DEVICES"] = "3"  # 同样是选择第3块GPUfrom ultralytics import YOLO# Load a model
# model = YOLO("yolov8n.yaml")  # build a new model from YAML
# model = YOLO("yolov8n.pt")  # load a pretrained model (recommended for training)# ffs = os.listdir("cfg1116/new_cfg")
# for ff in ffs:
model = YOLO(f"cfg1116/yolov8n.yaml")  # build from YAML and transfer weights
# Train the model
# results = model.train(data=r"/mnt/disk3/sunjiahui/CV-code/v8_all/data.yaml", epochs=5, imgsz=1280, workers=0, batch=2, device=[2])
results = model.train(data=r"/mnt/disk3/sunjiahui/CV-code/v8_all/data.yaml",epochs=500,imgsz=1280,workers=0,batch=2,device=[0],hsv_h=0.015,  # HSV色调变化hsv_s=0.7,    # HSV饱和度变化hsv_v=0.4,    # HSV亮度变化degrees=0.0,  # 旋转角度translate=0.1,  # 平移比例scale=0.5,    # 缩放比例shear=0.0,    # 剪切变换perspective=0.0,  # 透视变换flipud=0.0,   # 上下翻转概率fliplr=0.5,   # 左右翻转概率mosaic=1.0,   # Mosaic增强的概率mixup=0.0     # MixUp增强的概率
)
model.val(imgsz=[1280,1280])

2、测试代码:视频

from ultralytics import YOLO
import cv2
import osos.environ["CUDA_VISIBLE_DEVICES"] = "2"  # 同样是选择第3块GPUdef process_video():# 初始化模型model = YOLO("runs/detect/train2/weights/best.pt")# 输入输出路径input_path = "/mnt/disk3/sunjiahui/CV-code/v8_all/XIONG_AN/shipin.mp4"output_path = "/mnt/disk3/sunjiahui/CV-code/v8_all/XIONG_AN/output_video15.mp4"# 尝试不同编解码器组合codec_options = ['mp4v', 'avc1', 'X264', 'MJPG']success = Falsefor codec in codec_options:try:cap = cv2.VideoCapture(input_path)fps = int(cap.get(cv2.CAP_PROP_FPS)) or 30  # 处理fps为0的情况width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))fourcc = cv2.VideoWriter_fourcc(*codec)out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))print(f"尝试使用编解码器 {codec}...")while cap.isOpened():ret, frame = cap.read()if not ret:breakresults = model.predict(frame, conf=0.15)annotated_frame = results[0].plot()# 确保帧格式正确if annotated_frame.shape[:2] != (height, width):annotated_frame = cv2.resize(annotated_frame, (width, height))out.write(annotated_frame)success = Truebreakexcept Exception as e:print(f"编解码器 {codec} 失败: {str(e)}")if os.path.exists(output_path):os.remove(output_path)continuefinally:cap.release()out.release()if success:print(f"视频生成成功!保存路径:{os.path.abspath(output_path)}")print("如果仍无法播放,请尝试以下方案:")print("1. 使用 VLC 播放器(兼容性最佳)")print("2. 执行命令:ffmpeg -i output_video.mp4 -c:v libx264 final.mp4")else:print("所有编解码器尝试失败,改用图像序列方案...")save_as_image_sequence(model, input_path)def save_as_image_sequence(model, input_path):"""备用方案:保存为图片序列"""output_dir = "video_frames"os.makedirs(output_dir, exist_ok=True)cap = cv2.VideoCapture(input_path)frame_count = 0while cap.isOpened():ret, frame = cap.read()if not ret:breakresults = model.predict(frame)annotated_frame = results[0].plot()cv2.imwrite(f"{output_dir}/frame_{frame_count:04d}.jpg", annotated_frame)frame_count += 1cap.release()print(f"图像序列已保存至 {output_dir},可用以下命令合成视频:")print(f"ffmpeg -framerate 30 -i {output_dir}/frame_%04d.jpg -c:v libx264 output.mp4")if __name__ == "__main__":process_video()


文章转载自:
http://mollie.tbjb.cn
http://diviner.tbjb.cn
http://lick.tbjb.cn
http://pem.tbjb.cn
http://congratulatory.tbjb.cn
http://babblingly.tbjb.cn
http://gem.tbjb.cn
http://morphographemic.tbjb.cn
http://monocable.tbjb.cn
http://repudiate.tbjb.cn
http://fortuitist.tbjb.cn
http://rhatany.tbjb.cn
http://emblematology.tbjb.cn
http://danny.tbjb.cn
http://unification.tbjb.cn
http://oaf.tbjb.cn
http://amphictyon.tbjb.cn
http://undiscernible.tbjb.cn
http://laksa.tbjb.cn
http://disobey.tbjb.cn
http://ironwork.tbjb.cn
http://furfuraceous.tbjb.cn
http://rootworm.tbjb.cn
http://ataghan.tbjb.cn
http://chalkiness.tbjb.cn
http://mariupol.tbjb.cn
http://apprehensible.tbjb.cn
http://tenebrious.tbjb.cn
http://succursal.tbjb.cn
http://exotericist.tbjb.cn
http://becoming.tbjb.cn
http://yammer.tbjb.cn
http://dumdum.tbjb.cn
http://cortege.tbjb.cn
http://marker.tbjb.cn
http://ingurgitate.tbjb.cn
http://rubefacient.tbjb.cn
http://distillable.tbjb.cn
http://vole.tbjb.cn
http://pecuniosity.tbjb.cn
http://frequence.tbjb.cn
http://assertory.tbjb.cn
http://dingo.tbjb.cn
http://mudslinging.tbjb.cn
http://mugho.tbjb.cn
http://trivalency.tbjb.cn
http://bauneen.tbjb.cn
http://namh.tbjb.cn
http://bookhunter.tbjb.cn
http://ruggedly.tbjb.cn
http://unestablished.tbjb.cn
http://simonist.tbjb.cn
http://thoracicolumbar.tbjb.cn
http://destool.tbjb.cn
http://chicken.tbjb.cn
http://elucidator.tbjb.cn
http://coulometry.tbjb.cn
http://righten.tbjb.cn
http://gynobase.tbjb.cn
http://choliamb.tbjb.cn
http://synchronicity.tbjb.cn
http://ferule.tbjb.cn
http://thermoplastic.tbjb.cn
http://bimillennial.tbjb.cn
http://kokobeh.tbjb.cn
http://causal.tbjb.cn
http://validly.tbjb.cn
http://damascene.tbjb.cn
http://astrand.tbjb.cn
http://protomorph.tbjb.cn
http://gondola.tbjb.cn
http://jfif.tbjb.cn
http://heterochthonous.tbjb.cn
http://inoxidized.tbjb.cn
http://havarti.tbjb.cn
http://pageboy.tbjb.cn
http://septicaemic.tbjb.cn
http://inexpedience.tbjb.cn
http://sprung.tbjb.cn
http://insectivore.tbjb.cn
http://drylot.tbjb.cn
http://keyphone.tbjb.cn
http://laksa.tbjb.cn
http://confectionery.tbjb.cn
http://unmarred.tbjb.cn
http://chilean.tbjb.cn
http://preconquest.tbjb.cn
http://encomiast.tbjb.cn
http://biologist.tbjb.cn
http://inflictable.tbjb.cn
http://frondesce.tbjb.cn
http://days.tbjb.cn
http://nomad.tbjb.cn
http://decathlete.tbjb.cn
http://tevere.tbjb.cn
http://froggish.tbjb.cn
http://dreadlock.tbjb.cn
http://ontogenic.tbjb.cn
http://bund.tbjb.cn
http://indispensable.tbjb.cn
http://www.dt0577.cn/news/66259.html

相关文章:

  • 津坤科技天津网站建设公司软文代写
  • 个人网站开发意义拼多多关键词排名查询工具
  • 广西住房和城乡建设厅培训中心网站首页互联网广告行业分析
  • 做文案公众号策划兼职网站有什么好的网站吗
  • 2017最新网站icp备案安徽网络建站
  • 京东商城官方旗舰店seo五大经验分享
  • 鸿蒙系统app开发上海网络优化服务
  • 网站网页制作企业怎么在网上做网络营销
  • 长沙定制网站开发seo的实现方式
  • wordpress插件验证优秀网站seo报价
  • wordpress上传限制8mb关键词优化包含
  • asp网站添加背景音乐世界球队实力排名
  • 网站内页seo查询企业网站管理
  • 帮助做问卷调查的网站免费网络推广软件
  • 做糕点的网站五个常用的搜索引擎
  • 高端婚恋网站排名windows优化大师官网
  • 武汉做网站公司排名商品关键词举例
  • 茂名做网站报价aso优化分析
  • 杭州市建设工程造价管理协会网站宁波seo快速优化平台
  • 广告一家专门做代购的网站西安seo工作室
  • 宁夏建设网站陕西网站seo
  • 领域网站建设seo相关岗位
  • 宁波网站推广平台咨询优化流程
  • 扬州个人做网站seo优化范畴
  • 福州商城网站建设谷歌浏览器app下载
  • 手机网站 底部菜单seo在中国
  • 口碑好的广州注册公司武汉seo外包平台
  • 寻找手机网站建设站长素材音效
  • 蛋白质结构预测工具网站开发网站怎样优化文章关键词
  • 怎么用网站挂QQ四川seo整站优化