Zengyf-CVer commited on
Commit
35cbe8f
1 Parent(s): c828a61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -117
app.py CHANGED
@@ -1,7 +1,7 @@
1
- # Gradio YOLOv8 Det v1.2.1
2
  # 创建人:曾逸夫
3
- # 创建时间:2023-12-7
4
- # pip install gradio>=4.8.0
5
  # python gradio_yolov8_det_v1.py
6
 
7
 
@@ -581,130 +581,77 @@ def main(args):
581
  with gr.Row():
582
  gr.Markdown(GYD_SUB_TITLE)
583
  with gr.Row():
584
- with gr.Column(scale=1):
585
  with gr.Tabs():
586
  with gr.TabItem("目标检测与图像分割"):
587
  with gr.Row():
588
- inputs_img = gr.Image(
589
- image_mode="RGB", type="filepath", label="原始图片"
590
- )
591
- with gr.Row():
592
- device_opt = gr.Radio(
593
- choices=["cpu", "0", "1", "2", "3"],
594
- value="cpu",
595
- label="设备",
596
- )
597
- with gr.Row():
598
- inputs_model = gr.Dropdown(
599
- choices=model_names,
600
- value=model_name,
601
- type="value",
602
- label="模型",
603
- )
604
- with gr.Accordion("高级设置", open=True):
605
- with gr.Row():
606
- inputs_size = gr.Slider(
607
- 320,
608
- 1600,
609
- step=1,
610
- value=inference_size,
611
- label="推理尺寸",
612
- )
613
- max_det = gr.Slider(
614
- 1, 1000, step=1, value=max_detnum, label="最大检测数"
615
- )
616
- with gr.Row():
617
- input_conf = gr.Slider(
618
- 0,
619
- 1,
620
- step=slider_step,
621
- value=nms_conf,
622
- label="置信度阈值",
623
- )
624
- inputs_iou = gr.Slider(
625
- 0,
626
- 1,
627
- step=slider_step,
628
- value=nms_iou,
629
- label="IoU 阈值",
630
- )
631
- with gr.Row():
632
- obj_size = gr.Radio(
633
- choices=["所有尺寸", "小目标", "中目标", "大目标"],
634
- value="所有尺寸",
635
- label="目标尺寸",
636
- )
637
- with gr.Row():
638
- gr.ClearButton(inputs_img, value="清除")
639
- det_btn_img = gr.Button(value="检测", variant="primary")
640
  with gr.Row():
641
  gr.Examples(
642
  examples=EXAMPLES_DET,
643
  fn=yolo_det_img,
644
  inputs=[
645
- inputs_img,
646
- inputs_model,
647
- device_opt,
648
- inputs_size,
649
- input_conf,
650
- inputs_iou,
651
- max_det,
652
- obj_size,
653
- ],
654
  # outputs=[outputs_img, outputs_objSize, outputs_clsSize],
655
- cache_examples=False,
656
- )
657
 
658
  with gr.TabItem("图像分类"):
659
  with gr.Row():
660
- inputs_img_cls = gr.Image(
661
- image_mode="RGB", type="filepath", label="原始图片"
662
- )
663
- with gr.Row():
664
- inputs_model_cls = gr.Dropdown(
665
- choices=[
666
- "yolov8n-cls",
667
- "yolov8s-cls",
668
- "yolov8l-cls",
669
- "yolov8m-cls",
670
- "yolov8x-cls",
671
- ],
672
- value="yolov8s-cls",
673
- type="value",
674
- label="模型",
675
- )
676
- with gr.Row():
677
- gr.ClearButton(inputs_img, value="清除")
678
- det_btn_img_cls = gr.Button(value="检测", variant="primary")
679
  with gr.Row():
680
  gr.Examples(
681
  examples=EXAMPLES_CLAS,
682
  fn=yolo_cls_img,
683
  inputs=[inputs_img_cls, inputs_model_cls],
684
  # outputs=[outputs_img_cls, outputs_ratio_cls],
685
- cache_examples=False,
686
- )
687
-
688
- # -------- 输出 --------
689
- with gr.Column(scale=1):
690
- with gr.Tabs():
691
- with gr.TabItem("目标检测与图像分割"):
692
- # with gr.Row():
693
- # outputs_img = gr.Image(type="pil", label="检测图片")
694
- with gr.Row():
695
- outputs_img_slider = ImageSlider(position=0.5, label="检测图片")
696
- with gr.Row():
697
- outputs_imgfiles = gr.Files(label="图片下载")
698
- with gr.Row():
699
- outputs_objSize = gr.Label(label="目标尺寸占比统计")
700
- with gr.Row():
701
- outputs_clsSize = gr.Label(label="类别检测占比统计")
702
 
703
- with gr.TabItem("图像分类"):
704
- with gr.Row():
705
- outputs_img_cls = gr.Image(type="pil", label="检测图片")
706
- with gr.Row():
707
- outputs_ratio_cls = gr.Label(label="图像分类结果")
708
  with gr.Accordion("Gradio YOLOv8 Det 安装与使用教程"):
709
  gr.Markdown(
710
  """## Gradio YOLOv8 Det 安装与使用教程
@@ -718,29 +665,21 @@ def main(args):
718
  ```shell
719
  # 共享模式
720
  python gradio_yolov8_det_v1.py -is # 在浏览器中以共享模式打开,https://**.gradio.app/
721
-
722
  # 自定义模型配置
723
  python gradio_yolov8_det_v1.py -mc ./model_config/model_name_all.yaml
724
-
725
  # 自定义下拉框默认模型名称
726
  python gradio_yolov8_det_v1.py -mn yolov8m
727
-
728
  # 自定义类别名称
729
  python gradio_yolov8_det_v1.py -cls ./cls_name/cls_name_zh.yaml (目标检测与图像分割)
730
  python gradio_yolov8_det_v1.py -cin ./cls_name/cls_imgnet_name_zh.yaml (图像分类)
731
-
732
  # 自定义NMS置信度阈值
733
  python gradio_yolov8_det_v1.py -conf 0.8
734
-
735
  # 自定义NMS IoU阈值
736
  python gradio_yolov8_det_v1.py -iou 0.5
737
-
738
  # 设置推理尺寸,默认为640
739
  python gradio_yolov8_det_v1.py -isz 320
740
-
741
  # 设置最大检测数,默认为50
742
  python gradio_yolov8_det_v1.py -mdn 100
743
-
744
  # 设置滑块步长,默认为0.05
745
  python gradio_yolov8_det_v1.py -ss 0.01
746
  ```
@@ -787,4 +726,4 @@ if __name__ == "__main__":
787
  favicon_path="./icon/logo.ico", # 网页图标
788
  show_error=True, # 在浏览器控制台中显示错误信息
789
  quiet=True, # 禁止大多数打印语句
790
- )
 
1
+ # Gradio YOLOv8 Det v1.3.0
2
  # 创建人:曾逸夫
3
+ # 创建时间:2023-12-15
4
+ # pip install gradio>=4.9.1
5
  # python gradio_yolov8_det_v1.py
6
 
7
 
 
581
  with gr.Row():
582
  gr.Markdown(GYD_SUB_TITLE)
583
  with gr.Row():
 
584
  with gr.Tabs():
585
  with gr.TabItem("目标检测与图像分割"):
586
  with gr.Row():
587
+ with gr.Column(scale=1):
588
+ with gr.Row():
589
+ inputs_img = gr.Image(image_mode="RGB", type="filepath", label="原始图片")
590
+ with gr.Row():
591
+ device_opt = gr.Radio(choices=["cpu", "0", "1", "2", "3"], value="cpu", label="设备")
592
+ with gr.Row():
593
+ inputs_model = gr.Dropdown(choices=model_names, value=model_name, type="value", label="模型")
594
+ with gr.Accordion("高级设置", open=True):
595
+ with gr.Row():
596
+ inputs_size = gr.Slider(320, 1600, step=1, value=inference_size, label="推理尺寸")
597
+ max_det = gr.Slider(1, 1000, step=1, value=max_detnum, label="最大检测数")
598
+ with gr.Row():
599
+ input_conf = gr.Slider(0, 1, step=slider_step, value=nms_conf, label="置信度阈值")
600
+ inputs_iou = gr.Slider(0, 1, step=slider_step, value=nms_iou, label="IoU 阈值")
601
+ with gr.Row():
602
+ obj_size = gr.Radio(choices=["所有尺寸", "小目标", "中目标", "大目标"], value="所有尺寸", label="目标尺寸")
603
+ with gr.Row():
604
+ gr.ClearButton(inputs_img, value="清除")
605
+ det_btn_img = gr.Button(value='检测', variant="primary")
606
+ with gr.Column(scale=1):
607
+ # with gr.Row():
608
+ # outputs_img = gr.Image(type="pil", label="检测图片")
609
+ with gr.Row():
610
+ outputs_img_slider = ImageSlider(position=0.5, label="检测图片")
611
+ with gr.Row():
612
+ outputs_imgfiles = gr.Files(label="图片下载")
613
+ with gr.Row():
614
+ outputs_objSize = gr.Label(label="目标尺寸占比统计")
615
+ with gr.Row():
616
+ outputs_clsSize = gr.Label(label="类别检测占比统计")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
617
  with gr.Row():
618
  gr.Examples(
619
  examples=EXAMPLES_DET,
620
  fn=yolo_det_img,
621
  inputs=[
622
+ inputs_img, inputs_model, device_opt, inputs_size, input_conf, inputs_iou, max_det,
623
+ obj_size],
 
 
 
 
 
 
 
624
  # outputs=[outputs_img, outputs_objSize, outputs_clsSize],
625
+ cache_examples=False)
 
626
 
627
  with gr.TabItem("图像分类"):
628
  with gr.Row():
629
+ with gr.Column(scale=1):
630
+ with gr.Row():
631
+ inputs_img_cls = gr.Image(image_mode="RGB", type="filepath", label="原始图片")
632
+ with gr.Row():
633
+ inputs_model_cls = gr.Dropdown(choices=[
634
+ "yolov8n-cls", "yolov8s-cls", "yolov8l-cls", "yolov8m-cls", "yolov8x-cls"],
635
+ value="yolov8s-cls",
636
+ type="value",
637
+ label="模型")
638
+ with gr.Row():
639
+ gr.ClearButton(inputs_img, value="清除")
640
+ det_btn_img_cls = gr.Button(value='检测', variant="primary")
641
+ with gr.Column(scale=1):
642
+ with gr.Row():
643
+ outputs_img_cls = gr.Image(type="pil", label="检测图片")
644
+ with gr.Row():
645
+ outputs_ratio_cls = gr.Label(label="图像分类结果")
 
 
646
  with gr.Row():
647
  gr.Examples(
648
  examples=EXAMPLES_CLAS,
649
  fn=yolo_cls_img,
650
  inputs=[inputs_img_cls, inputs_model_cls],
651
  # outputs=[outputs_img_cls, outputs_ratio_cls],
652
+ cache_examples=False)
653
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
654
 
 
 
 
 
 
655
  with gr.Accordion("Gradio YOLOv8 Det 安装与使用教程"):
656
  gr.Markdown(
657
  """## Gradio YOLOv8 Det 安装与使用教程
 
665
  ```shell
666
  # 共享模式
667
  python gradio_yolov8_det_v1.py -is # 在浏览器中以共享模式打开,https://**.gradio.app/
 
668
  # 自定义模型配置
669
  python gradio_yolov8_det_v1.py -mc ./model_config/model_name_all.yaml
 
670
  # 自定义下拉框默认模型名称
671
  python gradio_yolov8_det_v1.py -mn yolov8m
 
672
  # 自定义类别名称
673
  python gradio_yolov8_det_v1.py -cls ./cls_name/cls_name_zh.yaml (目标检测与图像分割)
674
  python gradio_yolov8_det_v1.py -cin ./cls_name/cls_imgnet_name_zh.yaml (图像分类)
 
675
  # 自定义NMS置信度阈值
676
  python gradio_yolov8_det_v1.py -conf 0.8
 
677
  # 自定义NMS IoU阈值
678
  python gradio_yolov8_det_v1.py -iou 0.5
 
679
  # 设置推理尺寸,默认为640
680
  python gradio_yolov8_det_v1.py -isz 320
 
681
  # 设置最大检测数,默认为50
682
  python gradio_yolov8_det_v1.py -mdn 100
 
683
  # 设置滑块步长,默认为0.05
684
  python gradio_yolov8_det_v1.py -ss 0.01
685
  ```
 
726
  favicon_path="./icon/logo.ico", # 网页图标
727
  show_error=True, # 在浏览器控制台中显示错误信息
728
  quiet=True, # 禁止大多数打印语句
729
+ )