The fastai library simplifies training fast and accurate neural nets using modern best practices. See the fastai website to get started. The library is based on research into deep learning best practices undertaken at fast.ai
, and includes “out of the box” support for vision
, text
, tabular
, and collab
(collaborative filtering) models.
Data augmentation plays a huge role while working on Computer Vision task. Because the proper image transformation can drastically improve the generalization while building a deep learning model.
Read image:
= fastai::Image_create('files/cat.jpeg') img
Plot it:
%>% show() %>% plot() img
<center>
<img src="images/cat.png" alt="_" style="width: 350px;"/>
</center>
= list(img, img$flip_lr())
img_res = c('original', 'flipped')
titles
c(fig, axs) %<-% subplots(1,2)
for (i in 1:2) {
%>% show_image(ax = axs[[i]],
img_res[[i]] title=titles[i])
}
%>% plot(dpi = 250) img
<center>
<img src="images/flip.png" alt="_" style="width: 350px;"/>
</center>
c(fig, axs) %<-% subplots(2, 4)
for (i in 1:8) {
show_image(DihedralItem(p = 1.)(img, split_idx = 0), ctx = axs[[i]])
}
%>% plot(dpi = 250) img
<center>
<img src="images/dihedral.png" alt="_" style="width: 350px;"/>
</center>
= c(300L, 500L, 700L)
sz = paste('Size', sz)
size
c(fig, axs) %<-% subplots(1, 3, figsize = c(12, 4))
for (i in 1:3) {
show_image(img$crop_pad(sz[i]), ctx = axs[[i]], title = size[i])
}
%>% plot(dpi = 250) img
<center>
<img src="images/crop.png" alt="_" style="width: 350px;"/>
</center>
= c('border', 'reflection', 'zeros')
pad_modes
c(fig, axs) %<-% subplots(1, 3, figsize = c(12, 4))
for (i in 1:3) {
show_image(img$crop_pad(c(600L,700L), pad_mode = pad_modes[i]),
ctx = axs[[i]], title = pad_modes[i])
}
%>% plot(dpi = 250) img
<center>
<img src="images/modes.png" alt="_" style="width: 350px;"/>
</center>
c(fig, axs) %<-% subplots(1, 3, figsize = c(12, 4))
= RandomCrop(100)
ff
for (i in 1:3) {
show_image(ff(img), ctx = axs[[i]])
}
%>% plot(dpi = 250) img
<center>
<img src="images/random_crop.png" alt="_" style="width: 350px;"/>
</center>
c(fig, axs) %<-% subplots(1, 3, figsize = c(12, 4))
= RandomCrop(100L)
ff
for (i in 1:3) {
show_image(ff(img, split_idx = 1L), ctx = axs[[i]])
}
%>% plot(dpi = 250) img
<center>
<img src="images/center_crop.png" alt="_" style="width: 350px;"/>
</center>
= c('squish', 'pad', 'crop')
resize
c(fig, axs) %<-% subplots(1, 3, figsize = c(12, 4))
for (i in 1:3) {
= Resize(256, method = resize[i])
rsz show_image(rsz(img, split_idx = 0L), ctx = axs[[i]], title = resize[i])
}
%>% plot(dpi = 250) img
<center>
<img src="images/resize.png" alt="_" style="width: 350px;"/>
</center>
c(fig, axs) %<-% subplots(3, 3, figsize = c(9, 9))
= RandomResizedCrop(100)
ff
for (i in 1:9) {
show_image(ff(img), ctx = axs[[i]])
}
%>% plot(dpi = 250) img
<center>
<img src="images/random_resize.png" alt="_" style="width: 350px;"/>
</center>