Spaces:
Runtime error
Runtime error
valentynliubchenko
commited on
Commit
·
211cb30
1
Parent(s):
ad9be05
first commit
Browse files- app.py +42 -0
- convert_to_jpg.py +25 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
model = YOLO('./model/xViewyolov8m_v8_100e.pt')
|
| 7 |
+
example_list = [["examples/" + example] for example in os.listdir("examples")]
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def process_image(input_image):
|
| 12 |
+
# results = model(input_image)
|
| 13 |
+
# results = model.predict(input_image, conf=0.6, classes=range(0, 78))
|
| 14 |
+
results = model.predict(input_image, conf=0.6)
|
| 15 |
+
class_counts = {}
|
| 16 |
+
class_counts_str = "Class Counts:\n"
|
| 17 |
+
|
| 18 |
+
for r in results:
|
| 19 |
+
im_array = r.plot()
|
| 20 |
+
im_array = im_array.astype(np.uint8)
|
| 21 |
+
|
| 22 |
+
for box in r.boxes:
|
| 23 |
+
class_name = r.names[box.cls[0].item()]
|
| 24 |
+
class_counts[class_name] = class_counts.get(class_name, 0) + 1
|
| 25 |
+
|
| 26 |
+
for cls, count in class_counts.items():
|
| 27 |
+
class_counts_str += f"\n{cls}: {count}"
|
| 28 |
+
|
| 29 |
+
return im_array, class_counts_str
|
| 30 |
+
|
| 31 |
+
iface = gr.Interface(
|
| 32 |
+
fn=process_image,
|
| 33 |
+
inputs=gr.Image(),
|
| 34 |
+
outputs=["image", gr.Textbox(label="More info")],
|
| 35 |
+
title="YOLO Object detection. Trained on xView dataset. Medium model. Predict with conf=0.6",
|
| 36 |
+
description='''The xView dataset is composed of satellite images collected from WorldView-3 satellites at a 0.3m ground sample distance.\n
|
| 37 |
+
It contains over 1 million objects across 60 classes in over 1,400 km of imagery.''',
|
| 38 |
+
live=True,
|
| 39 |
+
examples=example_list
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
iface.launch()
|
convert_to_jpg.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
def convert_tiff_to_jpeg(tiff_path, jpeg_path):
|
| 5 |
+
try:
|
| 6 |
+
with Image.open(tiff_path) as img:
|
| 7 |
+
img.convert('RGB').save(jpeg_path, 'JPEG')
|
| 8 |
+
print(f"converted: {tiff_path} -> {jpeg_path}")
|
| 9 |
+
except Exception as e:
|
| 10 |
+
print(f"error converted {tiff_path}: {e}")
|
| 11 |
+
|
| 12 |
+
def batch_convert_tiff_to_jpeg(input_folder, output_folder):
|
| 13 |
+
if not os.path.exists(output_folder):
|
| 14 |
+
os.makedirs(output_folder)
|
| 15 |
+
|
| 16 |
+
for filename in os.listdir(input_folder):
|
| 17 |
+
if filename.endswith('.tif') or filename.endswith('.tiff'):
|
| 18 |
+
tiff_path = os.path.join(input_folder, filename)
|
| 19 |
+
jpeg_path = os.path.join(output_folder, filename.split('.')[0] + '.jpg')
|
| 20 |
+
convert_tiff_to_jpeg(tiff_path, jpeg_path)
|
| 21 |
+
|
| 22 |
+
input_folder = './examples'
|
| 23 |
+
output_folder = './examples2'
|
| 24 |
+
|
| 25 |
+
batch_convert_tiff_to_jpeg(input_folder, output_folder)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==3.49.0
|
| 2 |
+
numpy==1.26.0
|
| 3 |
+
opencv-python==4.9.0.80
|
| 4 |
+
ultralytics==8.1.10
|
| 5 |
+
mediapipe==0.10.7
|