Skip to main content

Yolov2keras

yolov2 implemented in tensorflow keras.

Supported dataset formats:-

  • Pascal Voc

Models Available:-

  • Yolo v2
  • Mobilenet

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.get_model(basemodel="yolov2",pretrained=True)
model = yod.models.get_model(basemodel="mobilenet",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]
mapcallback = yod.callbacks.MAPCallback(val_ds,iou_thres=0.5,per_nth_epoch=1)

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

model.fit(train_ds,validation_data=val_ds,epochs=5,verbose=1,callbacks=[mapcallback])

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

Inference

import yolov2keras as yod 
import tensorflow as tf


model_path="output/v1/"

# object_detector = yod.load_model(model_path)
object_detector = yod.load_model_from_weights(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)

Release files for YoloV2Keras 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for YoloV2Keras 0.0.6
File Size Uploaded
YoloV2Keras-0.0.6.tar.gz 19.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for YoloV2Keras 0.0.6
File Interpreter ABI Platform
YoloV2Keras-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 48.9 kB

Release files / YoloV2Keras-0.0.6.tar.gz

Download URL YoloV2Keras-0.0.6.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9eb37c9953c7c30073ddd474951f9386b04c1ddd5a9c38ade4dadb9723cd792f
BLAKE2b-256 checksum
How to use checksums
6cf6312b067636dce6224523427eac5f13c2a846ae36ad0d0c9ef30b75f8250a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / YoloV2Keras-0.0.6-py3-none-any.whl

Download URL YoloV2Keras-0.0.6-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6ea907ff05900419013164ce8a5491bcfbb20b88280a74953ac2256c42dd5e7
BLAKE2b-256 checksum
How to use checksums
e9f0dd65d73e39a9213633565e39516a940dea02dbede237179a364f691f8743
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page