Skip to main content

Yolo v2 library

Project description

Yolov2keras

yolov2 implemented in tensorflow keras.

Train and Save

import yolov2keras as yod 
import tensorflow as tf


train_image_dir="roboflow.voc/train/"
train_annotation_dir="roboflow.voc/train/"

val_image_dir="roboflow.voc/valid/"
val_annotation_dir="roboflow.voc/valid/"

# finding classnames of all the objects in the dataset
classnames_path = yod.dataset.VOCDataset.get_classnames_path(train_annotation_dir,val_annotation_dir)
yod.set_config(input_size=416,num_anchors=5,classnames_path=classnames_path)

# albumentations augmentations for making images a square
train_transform, val_transform, test_transform = yod.dataset.augmentations.default_augmentation()

# returns tf dataset objects
train_ds=yod.ParseDataset(train_image_dir,train_annotation_dir,format="PASCAL_VOC",augment=train_transform)
val_ds=yod.ParseDataset(val_image_dir,val_annotation_dir,format="PASCAL_VOC",augment=val_transform)

# finding the anchors of shape: (n,2)
anchors=yod.dataset.find_anchors(train_ds)
yod.set_anchors(anchors)

# convert to standard format to yolo v2 format
train_ds=yod.yoloDataset(train_ds,batch_size=4,drop_remainder=True)
val_ds=yod.yoloDataset(val_ds,batch_size=4)

# creating the model
model = yod.models.getYolov2(pretrained=True)
# model = yod.models.getMobileNet(pretrained=True)

optimizer = tf.keras.optimizers.Adam(learning_rate=1e-4, beta_1=0.9, beta_2=0.999, epsilon=1e-08)
metrics = [yod.metrics.iou_acc , yod.metrics.class_acc ] + [yod.losses.obj_loss,yod.losses.noobj_loss,yod.losses.box_loss,yod.losses.class_loss]

model.compile(optimizer=optimizer,loss=yod.losses.yolo_loss,metrics=metrics)

model.fit(train_ds,validation_data=val_ds,epochs=5,verbose=1)

# exporting the model
model_path="output/v1/"
yod.save(model_path,model)

Supported dataset formats:-

  • Pascal Voc

Models Available:-

  • Yolo v2
  • Mobilenet

Inference

import yolov2keras as yod 
import tensorflow as tf


model_path="output/v1/"

object_detector = yod.load_model(model_path)
object_detector.set_config(p_thres=0.5,nms_thres=0.3,image_size=[416])

img="Sample.jpg"

detections = object_detector.predict(img)
print(detections)

yod.inference.helper.show_objects(img,detections)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

YoloV2Keras-0.0.2.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

YoloV2Keras-0.0.2-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

Details for the file YoloV2Keras-0.0.2.tar.gz.

File metadata

  • Download URL: YoloV2Keras-0.0.2.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for YoloV2Keras-0.0.2.tar.gz
Algorithm Hash digest
SHA256 bbe22e4c3afb658e5b9304ca70924bc9bc62b77f90020de618f23f29b08c810d
MD5 6f9f9e29e49389b75d89d8aa8a5825fb
BLAKE2b-256 b499001e45dcb6fff47518b19519481e60c07255933ccde7091a72adcc5bca58

See more details on using hashes here.

File details

Details for the file YoloV2Keras-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: YoloV2Keras-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 26.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for YoloV2Keras-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a14b356dd3d8bb90d1757ad16bbeda74e03a3fbb64841cca0408a068329455d1
MD5 16aee476809694a2a9a3c199c9f54571
BLAKE2b-256 1bb9a5113bcfda7da0289219f5d14c05f8d518f44b3487b1ccbb3e8116f4964b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page