This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
OlderNewer