This file contains hidden or 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
from snippets.loader import * | |
from PIL import Image | |
import xml.etree.ElementTree as ET | |
from torchvision import transforms | |
device = 'cuda' | |
voc_labels = ('aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', | |
'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor') | |
label_map = {k: v + 1 for v, k in enumerate(voc_labels)} | |
label_map['background'] = 0 |
This file contains hidden or 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 sys; sys.path.append('/home/yyr/data/VOCdevkit/') | |
from load_data import VOCDataset, get_items, aug_trn | |
from snippets.loader import * | |
_2007_root = Path("/home/yyr/data/VOCdevkit/VOC2007") | |
_2012_root = Path("/home/yyr/data/VOCdevkit/VOC2012") | |
train_items = get_items(_2007_root, 'train') + get_items(_2012_root, 'train') | |
val_items = get_items(_2007_root, 'val') + get_items(_2012_root, 'val') | |
logger.info(f'\n{len(train_items)} training images\n{len(val_items)} validation images') | |
x = VOCDataset(train_items, tfms=aug_trn) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
project_url = 'https://github.com/sizhky/rcnn' | |
import os | |
if not os.path.exists('faster-rcnn'): | |
!git clone --quiet {project_url} rcnn | |
!pip install -q --upgrade imgaug fire torch_snippets | |
from google.colab import files | |
files.upload() # upload kaggle.json | |
!mkdir -p ~/.kaggle | |
!mv kaggle.json ~/.kaggle/ | |
!ls ~/.kaggle |
This file contains hidden or 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 = pd.read_csv('../validation-annotations-bbox.csv') | |
df['LabelName'] = df['LabelName'].map(lambda x: code2label[x]) | |
unique_classes = df['LabelName'].value_counts() | |
unique_classes = unique_classes[unique_classes < 501] | |
df = df[df['LabelName'].map(lambda x: x in unique_classes)] | |
print(df.ImageID.nunique()) | |
!mkdir -p open-images-mini | |
from tqdm import tqdm | |
for f in tqdm(df.ImageID.unique()): |
This file contains hidden or 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
class OpenImages(Dataset): | |
def __init__(self, image_folder, df): | |
self.root = image_folder | |
self.df = df | |
self.unique_images = df['ImageID'].unique() | |
def __len__(self): return len(self.unique_images) | |
def __getitem__(self, ix): | |
image_id = self.unique_images[ix] | |
image_path = f'{self.root}/{image_id}.jpg' | |
image = cv2.imread(image_path, 1)[...,::-1] # conver BGR to RGB |
This file contains hidden or 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
jt -t grade3 -fs 95 -tfs 11 -nfs 115 -cellw 95% -T | |
jt -t onedork -fs 95 -tfs 11 -nfs 115 -cellw 88% -T -N |
This file contains hidden or 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 torch, math | |
import torch.nn as nn | |
import torch.nn.functional as F | |
class RetinaNet(nn.Module): | |
num_anchors = 9 | |
def __init__(self, num_classes): | |
super(RetinaNet, self).__init__() | |
self.fpn = FPN50() | |
self.num_classes = num_classes |
This file contains hidden or 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
from IPython.core.magic import register_cell_magic | |
from IPython.display import HTML, display | |
def set_background(color): | |
script = ( | |
"var cell = this.closest('.jp-CodeCell');" | |
"var editor = cell.querySelector('.jp-Editor');" | |
"editor.style.background='{}';" | |
"this.parentNode.removeChild(this)" | |
).format(color) |
This file contains hidden or 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
document.getElementsByTagName("video")[0].playbackRate = 9001 |