Skip to content

Instantly share code, notes, and snippets.

View mrdbourke's full-sized avatar
🚀

Daniel Bourke mrdbourke

🚀
View GitHub Profile
@mrdbourke
mrdbourke / helpful-conda-commands.csv
Last active June 27, 2021 13:07
A list of helpful conda commands
Function Command
Get a list of all your environments conda env list
Get a list of all the packages installed in your current active environment conda list
Create an environment called [ENV_NAME] conda create --name [ENV_NAME]
Create an environment called [ENV_NAME] and install pandas and numpy conda create --name [ENV_NAME] pandas numpy
Activate an environment called [ENV_NAME] conda activate [ENV_NAME]
Create an environment folder called env in the current working directory (e.g. /Users/Daniel/project_1/) and install pandas and numpy conda create --prefix ./env pandas numpy
Activate an environment stored in a folder called env which is located within /Users/Daniel/project_1/ conda activate /Users/daniel/project_1/env
Deactivate an environment conda deactivate
Export your current active environment to a YAML file called environment (see why below) conda env export > environment.yaml
@mrdbourke
mrdbourke / helpful-conda-commands.md
Last active October 5, 2019 04:35
A list of helpful conda commands (markdown form)
Function Command
Get a list of all your environments conda env list
Get a list of all the packages installed in your current active environment conda list
Create an environment called [ENV_NAME] `conda create --name [ENV_
# Example of a Detectron2 label for image "1e2c50b991a82ee8.jpg"
[{'annotations': [{'bbox': [228.0, 12.0, 791.0, 858.0],
'bbox_mode': <BoxMode.XYXY_ABS: 0>,
'category_id': 0}],
'file_name': 'image_folder/1e2c50b991a82ee8.jpg', # this will change depending on where your images are stored
'height': 867,
'image_id': 33,
'width': 1024}]
# What downloading image labels from Open Images looks like
import pandas as pd
val_annots = pd.read_csv("https://storage.googleapis.com/openimages/v5/validation-annotations-bbox.csv")
val_annots.head()
import pandas as pd
classnames = pd.read_csv("https://storage.googleapis.com/openimages/v5/class-descriptions-boxable.csv",
names=["LabelName", "ClassName"])
classnames.head()
# Test our annotation formatting function
val_annots_formatted = format_annotations(image_folder="validation", # validation path
annotation_file="validation-annotations-bbox.csv", # validation annotations
target_classes=subset_classes) # (fireplace & coffeemaker)
val_annots_formatted.head()
# Create list of validation image dictionaries
val_img_dicts = get_image_dicts(image_folder="validation", # validation images
annotation_file="validation-annotations-bbox.csv", # these get formatted automatically
target_classes=target_classes) # list of target classes you're working with
>>> Using validation-annotations-bbox.csv for annotations...
On dataset: validation/
Classes we're using:
Coffeemaker 21
Name: ClassName, dtype: int64
# Object detection models from the Detectron2 model zoo
models_to_try = {
# model alias : model setup instructions
"R50-FPN-1x": "COCO-Detection/faster_rcnn_R_50_FPN_1x.yaml",
"R50-FPN-3x": "COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml",
"R101-FPN-3x": "COCO-Detection/faster_rcnn_R_101_FPN_3x.yaml",
"X101-FPN-3x": "COCO-Detection/faster_rcnn_X_101_32x8d_FPN_3x.yaml",
"RN-R50-1x": "COCO-Detection/retinanet_R_50_FPN_1x.yaml",
"RN-R50-3x": "COCO-Detection/retinanet_R_50_FPN_3x.yaml",
"RN-R101-3x": "COCO-Detection/retinanet_R_101_FPN_3x.yaml"
import numpy as np
import pandas as pd
np.random.seed(0)
sales_amounts = np.random.randint(20, size=(5, 3))
weekly_sales = pd.DataFrame(sales_amounts,
index=["Mon", "Tues", "Wed", "Thurs", "Fri"],
columns=["Almond butter", "Peanut butter", "Cashew butter"])
@mrdbourke
mrdbourke / fashion-mnist-classnames.py
Created November 3, 2021 01:21
Class names of FashionMNIST in Python list form (same order as original FashionMNIST)
# List of FashionMNIST labels, source: https://github.com/zalandoresearch/fashion-mnist
class_names = ["T-shirt/top",
"Trouser",
"Pullover",
"Dress",
"Coat",
"Sandal",
"Shirt",
"Sneaker",
"Bag",