Spaces:
Build error
Build error
| # AUTOGENERATED! DO NOT EDIT! File to edit: gradio_deploy.ipynb. | |
| # %% auto 0 | |
| __all__ = ['model', 'categories', 'input_img', 'output_img', 'examples', 'intf', 'predict_image', 'list_files_in_folder'] | |
| # %% gradio_deploy.ipynb 1 | |
| from fastai.vision.all import * | |
| import gradio as gr | |
| # %% gradio_deploy.ipynb 2 | |
| from ultralytics import YOLO | |
| model = YOLO('./model/best.pt') | |
| # %% gradio_deploy.ipynb 3 | |
| categories = ('Tarawa-class amphibious assault ship', | |
| 'air carrier', | |
| 'amphibious assault ship', | |
| 'amphibious transport dock', | |
| 'auxiliary ship', | |
| 'barge', | |
| 'bulk carrier', | |
| 'car carrier', | |
| 'combat boat', | |
| 'command ship', | |
| 'container ship', | |
| 'cruiser', | |
| 'destroyer', | |
| 'fishing boat', | |
| 'frigate', | |
| 'hovercraft', | |
| 'landing craft', | |
| 'liquefied gas ship', | |
| 'medical ship', | |
| 'oil tanker', | |
| 'passenger ship', | |
| 'submarine') | |
| def predict_image(img): | |
| m = model.predict(img)[0] | |
| m.save() | |
| # print(".\\results\\{}".format(l.path.split('\\')[-1])) | |
| a = PILImage.create("results_{}".format(m.path.split('\\')[-1])) | |
| # a.show() | |
| return a | |
| # %% gradio_deploy.ipynb 4 | |
| input_img = gr.Image(height=640,width=640) | |
| output_img = gr.Image(height=640,width=640) | |
| import os | |
| def list_files_in_folder(folder_path): | |
| # 获取该文件夹下所有文件名 | |
| file_names = [os.path.join(folder_path, file) for file in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, file))] | |
| return file_names | |
| # 示例用法 | |
| examples=list_files_in_folder("examples") | |
| examples | |
| intf = gr.Interface(fn=predict_image,inputs=input_img,outputs=output_img,examples=examples) | |
| intf.launch(inline=False) | |