Tooth-Cavity-Detection / tooth_decay_detection.py
Pulastya0's picture
Upload tooth_decay_detection.py
27553a2 verified
# -*- coding: utf-8 -*-
"""Tooth Decay Detection.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1tMmGs2M07jYAPI0z-FtK3edk1gxIQ6K-
"""
!pip install -q git+https://github.com/THU-MIG/yolov10.git
!wget -P -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10n.pt
!pip install -q roboflow
from roboflow import Roboflow
rf = Roboflow(api_key= "pZEBEeL3bfGXXSQHCJHH")
project = rf.workspace("meproject-4mubm/").project("mydata-wrg2p-t8nuc")
version = project.version(1)
dataset = version.download("yolov8")
!yolo task=detect mode=train epochs =35 batch = 32 plots= True\
model = '/content/-q/yolov10n.pt'\
data = '/content/mydata-1/data.yaml'
from ultralytics import YOLOv10
model_path = "/content/runs/detect/train/weights/best.pt"
model = YOLOv10(model_path)
result = model(source = "/content/mydata-1/valid/images", conf = 0.25, save =True)
import glob
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
images = glob.glob("/content/runs/detect/predict/*.jpg")
images_to_display = images[:10]
fig, axes =plt.subplots(2,5, figsize =(20,10))
for i , ax in enumerate(axes.flat):
if i < len(images_to_display):
img = mpimg.imread(images_to_display[i])
ax.imshow(img)
ax.axis('off')
else:
ax.axis('off')
plt.tight_layout()
plt.show()
result =model.predict(source = '/content/mydata-1/valid/images/1014_jpg.rf.e559597d59faaf5c86aa3c9c177620f6.jpg',imgsz = 640, conf = 0.25)
annotated_img =result[0].plot()
annotated_img[:, :, ::-1]
!pip install gradio
import gradio as gr
import cv2
import numpy as np
def predict(image):
result =model.predict(source =image,imgsz = 640, conf = 0.25)
annotated_image =result[0].plot()
annotated_image[:, :, ::-1]
return annotated_image
app = gr.Interface(
fn = predict,
inputs = gr.Image(type = "numpy", label ="Upload an Image"),
outputs = gr.Image(type = "numpy", label ="Detect a Tooth Cavity"),
title = "Tooth Cavity Detection Using YOLO V10 made by Pulastya ๐Ÿ˜Ž",
description = "Upload an Image ant eh YOLO V10 model will detect and Annotate the Tooth Decay"
)
app.launch()