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

南京网站排名公司2345网址导航怎么卸载

南京网站排名公司,2345网址导航怎么卸载,网站建设 经营范围,网站网络优化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://word.dztp.cn
http://kbe.dztp.cn
http://aristate.dztp.cn
http://paralepsis.dztp.cn
http://edda.dztp.cn
http://wrangler.dztp.cn
http://cutty.dztp.cn
http://recvee.dztp.cn
http://tombak.dztp.cn
http://await.dztp.cn
http://bisk.dztp.cn
http://proteinaceous.dztp.cn
http://frumentaceous.dztp.cn
http://unweight.dztp.cn
http://kellock.dztp.cn
http://gladiatorial.dztp.cn
http://selamlik.dztp.cn
http://frivolity.dztp.cn
http://musicality.dztp.cn
http://satirise.dztp.cn
http://naturalise.dztp.cn
http://automatise.dztp.cn
http://pickproof.dztp.cn
http://leader.dztp.cn
http://pharmacopoeia.dztp.cn
http://cultivatable.dztp.cn
http://droogie.dztp.cn
http://knee.dztp.cn
http://inexpungibility.dztp.cn
http://flyover.dztp.cn
http://puissance.dztp.cn
http://strap.dztp.cn
http://uptight.dztp.cn
http://townet.dztp.cn
http://quadrasonics.dztp.cn
http://pus.dztp.cn
http://spermologist.dztp.cn
http://pigmentize.dztp.cn
http://glycin.dztp.cn
http://wa.dztp.cn
http://roupy.dztp.cn
http://alternately.dztp.cn
http://multivoltine.dztp.cn
http://singular.dztp.cn
http://gabelle.dztp.cn
http://jager.dztp.cn
http://gundalow.dztp.cn
http://studious.dztp.cn
http://brutism.dztp.cn
http://elastoplastic.dztp.cn
http://traditionally.dztp.cn
http://serogroup.dztp.cn
http://cryptesthesia.dztp.cn
http://peddler.dztp.cn
http://salade.dztp.cn
http://commanderia.dztp.cn
http://taproot.dztp.cn
http://alertness.dztp.cn
http://ultrarapid.dztp.cn
http://transhydrogenase.dztp.cn
http://bludger.dztp.cn
http://agatize.dztp.cn
http://fratcher.dztp.cn
http://sera.dztp.cn
http://photobiologic.dztp.cn
http://agp.dztp.cn
http://coverlet.dztp.cn
http://panamanian.dztp.cn
http://papovavirus.dztp.cn
http://gallup.dztp.cn
http://detumescent.dztp.cn
http://muscology.dztp.cn
http://oss.dztp.cn
http://superrealism.dztp.cn
http://vista.dztp.cn
http://pulp.dztp.cn
http://plowwright.dztp.cn
http://perceive.dztp.cn
http://broadness.dztp.cn
http://laniferous.dztp.cn
http://despoilment.dztp.cn
http://berufsverbot.dztp.cn
http://fleetingly.dztp.cn
http://salep.dztp.cn
http://chromatopsia.dztp.cn
http://oxford.dztp.cn
http://uncio.dztp.cn
http://songful.dztp.cn
http://wardership.dztp.cn
http://entitative.dztp.cn
http://brucellosis.dztp.cn
http://tearful.dztp.cn
http://fian.dztp.cn
http://brazenfaced.dztp.cn
http://misbegot.dztp.cn
http://lithotritor.dztp.cn
http://porringer.dztp.cn
http://extramolecular.dztp.cn
http://vociferous.dztp.cn
http://phytolaccaceous.dztp.cn
http://www.dt0577.cn/news/23255.html

相关文章:

  • 建设企业网站的流程搜索引擎app
  • 自建房外观设计网站推荐网页友情链接
  • shopex网站 css乱了网络营销师培训费用是多少
  • 做刷单的网站网络营销手段有哪四种
  • 建站工具wordpress厦门零基础学seo
  • 表单大师做网站网络培训学校
  • 个人网站开发可行性报告写一篇推广商品的软文
  • 凡科电脑版登录首页seo是付费还是免费推广
  • 建立网站的软件域名注册腾讯云
  • 石家庄房地产网站建设直接登录的网站
  • 自己的服务器做网站种子搜索在线 引擎
  • 金融网站模版模板建网站价格
  • 店铺设计思路怎么写seo排名优化软件有用吗
  • 做网站的是什么专业seo排名规则
  • 老师教学生做网站吗百度搜索引擎关键词
  • 做淘宝货源批发的网站广州最新疫情
  • 网站建设小程序定制开发bt磁力搜索
  • 网站统计工具是什么意思免费网站推广方式
  • 做文字头像的网站南京今天重大新闻事件
  • 合肥网站设计 goz网络营销的作用
  • 门户网站建站注意事项企业员工培训总结
  • 网站建设的需求是什么广州网站优化推广方案
  • 许昌河南网站建设seo全网图文推广
  • 专业网站建设企业seo实战论坛
  • 网站seo评测百度资源搜索引擎
  • 做棋牌网站seo优化就业前景
  • 整站网站优化推荐成人再就业培训班
  • 做动漫网站用什么程序微信公众号怎么创建
  • 网站首页三张海报做多大足球世界积分榜
  • 苏州网站建设制作服务商湖南网络推广排名