| | import gradio.inputs |
| | import torch |
| | import gradio as gr |
| | from PIL import Image |
| | import tempfile |
| | import detect |
| | import os |
| | import shutil |
| |
|
| |
|
| | |
| |
|
| | def de(image): |
| | |
| | temp_path = tempfile.TemporaryDirectory(dir="./") |
| | temp_dir = temp_path.name |
| | |
| | temp_image_path = os.path.join(temp_dir, f"temp.jpg") |
| | |
| | img = Image.fromarray(image) |
| | img.save(temp_image_path) |
| | |
| | temp_result_path = os.path.join(temp_dir, "tempresult") |
| | |
| | detect.run(source=temp_image_path, data="test_image/FLIR.yaml", weights="./best.pt", project=f'./{temp_dir}',name = 'tempresult', hide_conf=True) |
| | |
| | temp_result_path = os.path.join(temp_result_path, os.listdir(temp_result_path)[0]) |
| | |
| | result_image = Image.open(temp_result_path).copy() |
| | |
| | temp_path.cleanup() |
| |
|
| | return result_image |
| |
|
| | example_image= [ |
| | ["./test_image/video-2SReBn5LtAkL5HMj2-frame-005072-MA7NCLQGoqq9aHaiL.jpg"], |
| | ["./test_image/video-2rsjnZFyGQGeynfbv-frame-003708-6fPQbB7jtibwaYAE7.jpg"], |
| | ["./test_image/video-2SReBn5LtAkL5HMj2-frame-000317-HTgPBFgZyPdwQnNvE.jpg"], |
| | ["./test_image/video-jNQtRj6NGycZDEXpe-frame-002515-J3YntG8ntvZheKK3P.jpg"], |
| | ["./test_image/video-kDDWXrnLSoSdHCZ7S-frame-003063-eaKjPvPskDPjenZ8S.jpg"], |
| | ["./test_image/video-r68Yr9RPWEp5fW2ZF-frame-000333-X6K5iopqbmjKEsSqN.jpg"] |
| | ] |
| |
|
| | iface = gr.Interface(fn=de, inputs=gr.Image(label="上传一张红外图像,仅支持jpg格式"), outputs="image", examples=example_image, share=True) |
| | iface.launch(share=True) |
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|