Skip to content

Instantly share code, notes, and snippets.

View sandeeppanda22's full-sized avatar
🎯
Focusing

Sandeep Kumar Panda sandeeppanda22

🎯
Focusing
  • Bhubaneswar
  • 23:09 (UTC +05:30)
View GitHub Profile
@sandeeppanda22
sandeeppanda22 / 0.useful.md
Created November 17, 2020 07:20 — forked from felipemoraes/0.useful.md
Machine Learning Interview Questions
def display_yolo(file, model, score_threshold, iou_threshold):
'''
Display predictions from YOLO model.
Parameters
----------
- file : string list : list of images path.
- model : YOLO model.
- score_threshold : threshold used for filtering predicted bounding boxes.
- iou_threshold : threshold used for non max suppression.
def train(epochs, model, train_dataset, val_dataset, steps_per_epoch_train, steps_per_epoch_val, train_name = 'train'):
'''
Train YOLO model for n epochs.
Eval loss on training and validation dataset.
Log training loss and validation loss for tensorboard.
Save best weights during training (according to validation loss).
Parameters
----------
- epochs : integer, number of epochs to train the model.
def yolov2_loss(detector_mask, matching_true_boxes, class_one_hot, true_boxes_grid, y_pred, info=False):
'''
Calculate YOLO V2 loss from prediction (y_pred) and ground truth tensors (detector_mask,
matching_true_boxes, class_one_hot, true_boxes_grid,)
Parameters
----------
- detector_mask : tensor, shape (batch, size, GRID_W, GRID_H, anchors_count, 1)
1 if bounding box detected by grid cell, else 0
- matching_true_boxes : tensor, shape (batch_size, GRID_W, GRID_H, anchors_count, 5)
def augmentation_generator(yolo_dataset):
'''
Augmented batch generator from a yolo dataset
Parameters
----------
- YOLO dataset
Returns
-------
val_dataset = None
val_dataset= get_dataset(val_image_folder, val_annot_folder, LABELS, VAL_BATCH_SIZE)
train_dataset = None
train_dataset= get_dataset(train_image_folder, train_annot_folder, LABELS, TRAIN_BATCH_SIZE)
@sandeeppanda22
sandeeppanda22 / reading_dataset.py
Last active August 21, 2020 05:03
Reading the train and test dateset
def parse_function(img_obj, true_boxes):
x_img_string = tf.io.read_file(img_obj)
x_img = tf.image.decode_png(x_img_string, channels=3) # dtype=tf.uint8
x_img = tf.image.convert_image_dtype(x_img, tf.float32) # pixel value /255, dtype=tf.float32, channels : RGB
return x_img, true_boxes
def get_dataset(img_dir, ann_dir, labels, batch_size):
'''
Create a YOLO dataset
class WeightReader:
def __init__(self, weight_file):
self.offset = 4
self.all_weights = np.fromfile(weight_file, dtype='float32')
def read_bytes(self, size):
self.offset = self.offset + size
return self.all_weights[self.offset-size:self.offset]
def reset(self):
# Yolo model (thanks to https://github.com/experiencor/keras-yolo2)
input_image = tf.keras.layers.Input((IMAGE_H, IMAGE_W, 3), dtype='float32')
# Layer 1
x = Conv2D(32, (3,3), strides=(1,1), padding='same', name='conv_1', use_bias=False)(input_image)
x = BatchNormalization(name='norm_1')(x)
x = LeakyReLU(alpha=0.1)(x)
x = MaxPooling2D(pool_size=(2, 2))(x)