Important: This notebook will only work with fastai-0.7.x. Do not try to run any fastai-1.x code from this path in the repository because it will load fastai-0.7.x
In [ ]:
%reload_ext autoreload
%autoreload 2
%matplotlib inline
# This file contains all the main external libs we'll use
from fastai.imports import *
from fastai.transforms import *
from fastai.plots import *
from fastai.dataset import *
In [ ]:
PATH = "data/fish/"
PATH = "/data2/yinterian/fisheries-kaggle/"
In [ ]:
fnames,corner_labels,_,_ = parse_csv_labels(f'{PATH}trn_bb_corners_labels', skip_header=False)
In [ ]:
def get_x(f):
return open_image(f'{PATH}/images/{f}')
In [ ]:
f = 'img_02642.jpg'
x = get_x(f)
y = np.array(corner_labels[f], dtype=np.float32)
y
Out[ ]:
In [ ]:
x.shape
Out[ ]:
In [ ]:
rows = np.rint([y[0], y[0], y[2], y[2]]).astype(int)
rows
Out[ ]:
In [ ]:
cols = np.rint([y[1], y[3], y[1], y[3]]).astype(int)
cols
Out[ ]:
In [ ]:
corner_labels["img_02642.jpg"]
Out[ ]:
In [ ]:
def create_corner_rect(bb, color='red'):
bb = np.array(bb, dtype=np.float32)
return plt.Rectangle((bb[1], bb[0]), bb[3]-bb[1], bb[2]-bb[0], color=color, fill=False, lw=3)
def show_corner_bb(f='img_04908.jpg'):
file_path = f'{PATH}images/{f}'
bb = corner_labels[f]
plots_from_files([file_path])
plt.gca().add_patch(create_corner_rect(bb))
In [ ]:
show_corner_bb(f = 'img_02642.jpg')
In [ ]:
def create_rect(bb, color='red'):
return plt.Rectangle((bb[1], bb[0]), bb[3]-bb[1], bb[2]-bb[0], color=color, fill=False, lw=3)
def plotXY(x,y):
plots([x])
plt.gca().add_patch(create_rect(y))
In [ ]:
plotXY(x,y)
In [ ]:
xx, yy = Scale(sz=350, tfm_y=TfmType.COORD)(x, y)
In [ ]:
plotXY(xx,yy)
In [ ]:
xx, yy = Scale(sz=350, tfm_y=TfmType.PIXEL)(x, x)
plots([xx, yy])
In [ ]:
xx, yy = RandomScale(sz=350, max_zoom=1.1, tfm_y=TfmType.COORD)(x, y)
plotXY(xx,yy)
print(yy)
print(y)
In [ ]:
xx, yy = RandomScale(sz=350, max_zoom=1.1, tfm_y=TfmType.PIXEL)(x, x)
plots([xx, yy])
In [ ]:
xx, yy = RandomCrop(targ=350, tfm_y=TfmType.COORD)(x, y)
In [ ]:
plotXY(xx,yy)
In [ ]:
xx, yy = RandomCrop(350, tfm_y=TfmType.PIXEL)(x, x)
plots([xx, yy])
In [ ]:
xx, yy = NoCrop(350, tfm_y=TfmType.COORD)(x, y)
In [ ]:
print(yy)
plotXY(xx,yy)
In [ ]:
xx, yy = NoCrop(350, tfm_y=TfmType.PIXEL)(x, x)
plots([xx, yy])
In [ ]:
xx, yy = CenterCrop(350, tfm_y=TfmType.COORD)(x, y)
In [ ]:
plotXY(xx,yy)
In [ ]:
xx, yy = CenterCrop(350, tfm_y=TfmType.PIXEL)(x, x)
plots([xx, yy])
In [ ]:
xx, yy = RandomDihedral(TfmType.COORD)(x, y)
In [ ]:
print(yy)
In [ ]:
plotXY(xx,yy)
In [ ]:
xx, yy = RandomDihedral(tfm_y=TfmType.PIXEL)(x, x)
In [ ]:
plots([xx,yy])
In [ ]:
xx, yy = RandomFlip(TfmType.COORD)(x, y)
print(yy)
plotXY(xx,yy)
In [ ]:
xx, yy = RandomFlip(TfmType.PIXEL)(x, x)
plots([xx,yy])
In [ ]:
xx, yy = RandomLighting(0.5, 0.5)(x, y)
plotXY(xx,yy)
In [ ]:
# talk to Jeremy about this
xx, yy = RandomLighting(0.5, 0.5, TfmType.PIXEL)(x, x)
plots([xx,yy])
In [ ]:
xx, yy = RandomRotate(deg=30, p=1, tfm_y=TfmType.COORD)(x, y)
plotXY(xx,yy)
print(yy)
In [ ]:
In [ ]:
xx, yy = RandomRotate(130,p=1.0, tfm_y=TfmType.COORD)(x, y)
plotXY(xx,yy)
In [ ]:
xx, yy = RandomRotate(0.5, 0.5, TfmType.PIXEL)(x, x)
plots([xx,yy])