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 random | |
import os | |
import torch | |
import numpy as np | |
def set_seed(seed): | |
random.seed(seed) | |
os.environ['PYTHONHASHSEED'] = str(seed) | |
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
learn = cnn_learner(dls, resnet34, pretrained=True, metrics=accuracy).to_fp16() | |
learn.fit_one_cycle(4) | |
learn.save('stage_1') | |
#Understand which classes are misclassified | |
interp = ClassificationInterpretation.from_learner(learn) | |
losses,idxs = interp.top_losses() | |
interp.plot_top_losses(9, figsize=(15,10)) | |
interp.most_confused(min_val=3) |
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
batch_tfms = [*aug_transforms(size=224, max_warp=0), Normalize.from_stats(*imagenet_stats)] | |
item_tfms = RandomResizedCrop(460, min_scale=0.75, ratio=(1.,1.)) | |
bs=128 | |
dls = ImageDataLoaders.from_folder(data_path, train='train', valid='val', batch_tfms=batch_tfms, | |
item_tfms=item_tfms, bs=bs) |
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
#Mixed precision model to train | |
learn = cnn_learner(dls, resnet18, pretrained=True, metrics=[accuracy_multi]).to_fp16() | |
#Train only the classifier using one cycle policy, with default optimizer(ADAM) and learning rate. | |
learn.fit_one_cycle(4) | |
#Save the trained model | |
learn.save('stage_1') | |
#Unfreeze the model, now entire model is available for training | |
learn.unfreeze() |
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
get_x = lambda x:CELEBA_PATH/f'{x[0]}' | |
get_y = lambda x:[headers[index+1] for index,val in enumerate(x[1:]) if val == 1] | |
batch_tfms = [*aug_transforms(size=224, max_warp=0), Normalize.from_stats(*imagenet_stats)] | |
item_tfms = RandomResizedCrop(460, min_scale=0.75, ratio=(1.,1.)) | |
bs=64 | |
celleba_data = DataBlock(blocks=(ImageBlock, MultiCategoryBlock), | |
get_x=get_x, | |
splitter=RandomSplitter(), | |
get_y=get_y, |
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
from fastai2.data.all import * | |
from fastai2.vision.all import * | |
from fastai2.callback.all import * |
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
var funcArray_1 = []; | |
var funcArray_2 = []; | |
//IIFE of type 1 | |
for (var i = 0; i < 10; i++) { | |
funcArray_1.push(function(val){ | |
return function() { console.log(val); } | |
}(i)); | |
} | |
console.log(i); // 10 |
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
var Arr = [3, 6, 9, 12, 15, 18, 21]; | |
Arr.author="Gurucharan"; | |
//Using legacy for loop | |
console.log('==============[Legacy for loop]=============='); | |
for (var i = 0; i < Arr.length; ++i) { | |
console.log("index is of type", typeof i, Arr[i]); | |
} | |
//Using forEach |
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
let colors = [ "red", "green", "blue" ]; | |
let iter = colors.entries(); | |
let entry; | |
while (!(entry = iter.next()).done) { | |
console.log(entry.value); | |
} |
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
let iterable = { | |
0: 'a', | |
1: 'b', | |
2: 'c', | |
length: 3, | |
[Symbol.iterator]() { | |
var keys = Object.keys(this).sort(); | |
var index = 0; | |
return { |
NewerOlder