YOLOv5 applied to James Webb Space Telescope (JWST) Image¶

The analysis performed here employed:

  • Source of images: James Webb Space Telescope
  • LabelImg framework for computer vision annotation
  • Roboflow for image streamlining, format conversion, and training, validation and testing sets formation
  • YOLOv5 deep network

Requirements Installation¶

In [3]:
!git clone https://github.com/ultralytics/yolov5  # clone repo
%cd yolov5
%pip install -qr requirements.txt # install dependencies
%pip install -q roboflow

import torch
import os
from IPython.display import Image, clear_output  # to display images

print(f"Setup complete. Using torch {torch.__version__} ({torch.cuda.get_device_properties(0).name if torch.cuda.is_available() else 'CPU'})")
[Errno 2] No such file or directory: 'yolov5'
/content/yolov5
Setup complete. Using torch 1.12.0+cu113 (Tesla T4)

Image Annotation and Streamlining¶

Here we can see the result of the images, after the annotation and streamlining stages, from Roboflow website.

image.png

In [4]:
from roboflow import Roboflow
rf = Roboflow(model_format="yolov5", notebook="ultralytics")
upload and label your dataset, and get an API KEY here: https://app.roboflow.com/?model=yolov5&ref=ultralytics
In [5]:
# set up environment
os.environ["DATASET_DIRECTORY"] = "/content/datasets"
In [6]:
#after following the link above, recieve python code with these fields filled in

from roboflow import Roboflow
rf = Roboflow(api_key=API_KEY)
project = rf.workspace("silas-data").project("jwst-stars")
dataset = project.version(1).download("yolov5")
loading Roboflow workspace...
loading Roboflow project...
Downloading Dataset Version Zip in /content/datasets/JWST-stars-1 to yolov5pytorch: 100% [1129152 / 1129152] bytes
Extracting Dataset Version Zip to /content/datasets/JWST-stars-1 in yolov5pytorch:: 100%|██████████| 136/136 [00:00<00:00, 1948.56it/s]

Train YOLOv5 model¶

We have some hyperparameters:

  • img: define input image size
  • batch: determine batch size
  • epochs: define the number of training epochs
  • weights: initial weights of the network