Vignana-Jyothi / kp-learnings

Curiosity & Learnings
GNU General Public License v3.0
1 stars 0 forks source link

[YOLO] Use latest YOLO model to run basic deep learning #4

Closed head-iie-vnr closed 4 months ago

head-iie-vnr commented 4 months ago

Objective

head-iie-vnr commented 4 months ago

Install YOLOv8 in Your Existing Environment

Install the YOLOv8 package using pip:

pip install ultralytics

Start Jupyter Notebook

Start Jupyter Notebook while your environment is activated:

jupyter notebook

Write Your YOLOv8 Code

In the new notebook, write your YOLOv8 code. Below is an example to get you started:

# Import YOLOv8 from the ultralytics package
from ultralytics import YOLO

# Load a pretrained YOLOv8 model (you can also train your own model)
model = YOLO('yolov8n.pt')  # You can change 'yolov8n.pt' to other versions like 'yolov8s.pt', 'yolov8m.pt', etc.

# Load an image
img = 'path/to/your/image.jpg'  # Replace with your image path

# Perform inference
results = model(img)

# Print results
results.print()

# Show the results
results.show()

Save the notebook as YOLOv8_Jupyter_Notebook.ipynb.

Commit and Push to GitHub

Add the notebook to your repository, commit, and push it:


git add YOLOv8_Jupyter_Notebook.ipynb
git commit -m "Add YOLOv8 Jupyter Notebook for issue #4"
git push origin main
head-iie-vnr commented 4 months ago

To reduce the size of your Jupyter Notebook (.ipynb file), you can follow several strategies:

1. Clear All Outputs

Clear the outputs of all cells in your notebook. This can significantly reduce the file size as images and large data outputs are removed.

2. Convert Notebook to a Script

If you want to keep a clean version of your code without outputs, you can convert your notebook to a Python script.

3. Use a Tool to Clean Notebooks

There are tools designed to strip outputs and metadata from Jupyter Notebooks.

4. Compress Images

If your notebook contains many images, consider compressing them before inserting into the notebook. Tools like Pillow can help with this:

from PIL import Image

img = Image.open('path/to/image.jpg')
img.save('path/to/compressed_image.jpg', quality=85)

5. Save Large Data Externally

If your notebook generates large data, consider saving it to external files (e.g., CSV, JSON, HDF5) instead of displaying it directly in the notebook.

import pandas as pd

# Save DataFrame to CSV instead of displaying it
df.to_csv('data.csv')
head-iie-vnr commented 4 months ago

Tried the same with other Models.

Original Image

sample_image

Nano

nano_model

Small

small_model

Medium

medium_model

Large

large_model

XL

xl_model