Skip to content

Instantly share code, notes, and snippets.

View bala-codes's full-sized avatar
👋
Good Vibes Only

Balakrishna Kumar V bala-codes

👋
Good Vibes Only
View GitHub Profile
@bala-codes
bala-codes / Simple_Function.py
Last active July 19, 2020 18:53
Simple Python Function
import argparse
def add_and_display(number_1, number_2, permission, display_value):
if permission :
print(display_value, number_1 + number_2)
if __name__ == "__main__":
add_and_display(number_1 = 10, number_2 = 20, permission = True,
display_value = "Adding two numbers")
@bala-codes
bala-codes / argparse.py
Last active July 20, 2020 04:49
# Simple Demonstration of Python Argparser in command line arguments
# Simple Demonstration of Python Argparser in command line arguments# Simple Demonstration of Python Argparser in command line arguments
import argparse
from distutils.util import strtobool
def add_and_display(args):
print(args)
print()
if args.permissions :
if args.operation == "add":
print("Adding two numbers :", args.number_1 + args.number_2)
@bala-codes
bala-codes / argparse-args.py
Created July 20, 2020 10:28
# Simple Demonstration of Python Argparser with positional and optional arguments
# Simple Demonstration of Python Argparser in command line arguments with positional and optional arguments
import argparse
from distutils.util import strtobool
def add_and_display(args):
print(args)
print()
if args.permissions :
if args.operation == "add":
print("Adding two numbers :", args.number_1 + args.number_2 + args.number_3 + args.number_4)
else:
@bala-codes
bala-codes / preprocess1.py
Last active August 12, 2020 16:17
BCC-Datapreprocess
# Dataset Extraction from github
!git clone 'https://github.com/Shenggan/BCCD_Dataset.git'
import os, sys, random, shutil
import xml.etree.ElementTree as ET
from glob import glob
import pandas as pd
from shutil import copyfile
import pandas as pd
from sklearn import preprocessing, model_selection
@bala-codes
bala-codes / BCC-preprocess2.py
Created August 12, 2020 16:23
BCCD Preprocess
img_width = 640
img_height = 480
def width(df):
return int(df.xmax - df.xmin)
def height(df):
return int(df.ymax - df.ymin)
def x_center(df):
return int(df.xmin + (df.width/2))
def y_center(df):
@bala-codes
bala-codes / BCC-Preprocess3.py
Last active August 12, 2020 16:33
BCC-Preprocess3
df_train, df_valid = model_selection.train_test_split(df, test_size=0.1, random_state=13, shuffle=True)
print(df_train.shape, df_valid.shape)
os.mkdir('/content/bcc/')
os.mkdir('/content/bcc/images/')
os.mkdir('/content/bcc/images/train/')
os.mkdir('/content/bcc/images/valid/')
os.mkdir('/content/bcc/labels/')
os.mkdir('/content/bcc/labels/train/')
!git clone 'https://github.com/ultralytics/yolov5.git'
!pip install -qr '/content/yolov5/requirements.txt' # install dependencies
## Create a yaml file and move it into the yolov5 folder ##
shutil.copyfile('/content/bcc.yaml', '/content/yolov5/bcc.yaml')
@bala-codes
bala-codes / Yolov5-model_train.py
Created August 12, 2020 16:55
BCC-model_build
# Start tensorboard (optional)
%load_ext tensorboard
%tensorboard --logdir runs/
!python yolov5/train.py --img 640 --batch 8 --epochs 100 \
--data bcc.yaml --cfg models/yolov5s.yaml --name BCCM
## TO PREDICT IMAGES IN A FOLDER ##
!python yolov5/detect.py --source /content/bcc/images/valid/
--weights '/content/drive/My Drive/Machine Learning Projects/YOLO/best_yolov5_BCCM.pt'
--output '/content/inference/output'
## TO PREDICT A SINGLE IMAGE FILE ##
output = !python yolov5/detect.py --source /content/bcc/images/valid/BloodImage_00000.jpg
--weights '/content/drive/My Drive/Machine Learning Projects/YOLO/best_yolov5_BCCM.pt'
@bala-codes
bala-codes / Yolov5-prod.py
Last active August 12, 2020 17:32
Yolo_to_production
import os, sys, random
from glob import glob
import matplotlib.pyplot as plt
%matplotlib inline
!pip install -qr '/content/drive/My Drive/Machine Learning Projects/YOLO/SOURCE/requirements.txt' # install dependencies
## Add the path where you have stored the neccessary supporting files to run detect.py ##
## Replace this with your path.##
sys.path.insert(0, '/content/drive/My Drive/Machine Learning Projects/YOLO/SOURCE/')
print(sys.path)