Kaggle competition: Digit Recognizer
tst_preds =(PRED0 + 2*PRED1 + PRED2 + PRED3)/5<save_to_csv>
%matplotlib inline
seed = 4098653265
seed_all(seed, det_cudnn=True)
 def mnist_learner(data: ImageDataBunch, model_name: Optional[str] = None)-> Learner:
cbs =(( partial(SaveModelCallback, monitor='accuracy', name=model_name),)
 if model_name else None)
 lrn = cnn_learner(data, models.resnet152, metrics=accuracy,
opt_func=partial(optim.SGD, momentum=0.9),
callback_fns=cbs)
 seed = 224391980
seed_all(seed, det_cudnn=True)
 return lrn
test = pd.DataFrame()
test['image_id'] = list(os.listdir(f'{DATA_DIR}/test_images/'))
test['label'] = np.argmax(tst_preds, axis=1)
 test.to_csv('submission.csv', index=False )<define_variables>
data = ImageDataBunch.from_csv('data', test='test', num_workers=0)
 data.test_ds.x.items = np.array(sorted(data.test_ds.x.items, key=attrgetter('stem')))
 learner = mnist_learner(data, 'best-freezed')
 learner.lr_find()
learner.recorder.plot(suggestion=True )
CONFIG_NAME = 'stacking12.yml'
debug = False
STAGE2_DIR = '.. /input/train-stacking-2dcnn-ver3/output'<define_variables>
learner.fit_one_cycle(30, 1.3e-2 )
CONFIG_PATH = f'{STAGE2_DIR}/{CONFIG_NAME}'
with open(CONFIG_PATH)as f:
config = yaml.load(f)
 INFO = config['info']
TAG = config['tag']
CFG = config['cfg']
OUTPUT_DIR = './'
DATA_PATH = '.. /input/cassava-leaf-disease-classification'<define_variables>
learner = mnist_learner(data ).load('best-freezed')
 corr_args = DatasetFormatter.from_most_unsure(learner, 100)
 corr = PredictionsCorrector(*corr_args )
<import_modules>
corr.corrections = {
275: 5, 927: 6, 3080: 0, 3162: 3, 3485: 8, 3700: 5, 3740: 9,
4680: 1, 5215: 1, 5276: 1, 5928: 5, 6789: 3, 7026: 4, 9040: 2,
9202: 7, 9744: 3, 9814: 4, 9924: 2, 10344: 9, 11370: 8, 11746: 8,
11862: 8, 12620: 8, 12864: 9, 14579: 9, 14742: 0, 16204: 9,
16281: 5, 16452: 4, 17589: 8, 17931: 5, 18166: 1, 19351: 1,
19896: 8, 20052: 9, 20509: 5, 20665: 1, 20946: 3, 21388: 1,
22253: 8, 22465: 4, 22527: 1, 22632: 8, 22823: 4, 23874: 1,
24015: 4, 24155: 4, 24662: 8, 25527: 6, 25915: 8, 26913: 3,
27372: 3, 27402: 2
}
corr.show_corrections(9, figsize=(14.5, 11))
sys.path.append('.. /input/pytorch-image-models/pytorch-image-models-master')
 Compose, OneOf, Normalize, Resize, RandomResizedCrop, RandomCrop, HorizontalFlip, VerticalFlip,
RandomBrightness, RandomContrast, RandomBrightnessContrast, Rotate, ShiftScaleRotate, Cutout,
IAAAdditiveGaussianNoise, Transpose, CenterCrop 
)
 warnings.filterwarnings('ignore')
 if CFG['debug']:
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 else:
device = torch.device('cuda')
 start_time = datetime.datetime.now()
start_time_str = start_time.strftime('%m%d%H%M' )<load_from_csv>
preds = corr.corrected_labels()
submission = pd.DataFrame(
 preds, columns=('Label',),
index=pd.Index(( 1 + int(p.stem)for p in data.test_ds.x.items),
name='ImageId')
 ).sort_index()
submission.to_csv('submission.csv')
 submission.head(10 )
train = pd.read_csv(f'{DATA_PATH}/train.csv')
 test = pd.read_csv(f'{DATA_PATH}/sample_submission.csv')
 label_map = pd.read_json(f'{DATA_PATH}/label_num_to_disease_map.json',
orient='index')
 if CFG['debug']:
train = train.sample(n=1000, random_state=CFG['seed'] ).reset_index(drop=True )<define_variables>
! echo 64e2b22ef2bf4e7f8b179c497a81aeea11761ce1e242083a44c42a20c8a52c65 \
submission.csv | sha256sum -c