def main(epochs):
    Task.init(project_name="examples", task_name="fastai v1")

    path = untar_data(URLs.MNIST_SAMPLE)

    data = ImageDataBunch.from_folder(path, ds_tfms=(rand_pad(2, 28), []), bs=64, num_workers=0)
    data.normalize(imagenet_stats)

    learn = cnn_learner(data, models.resnet18, metrics=accuracy)

    accuracy(*learn.get_preds())
    learn.fit_one_cycle(epochs, 0.01)
Exemple #2
0
def get_accuracy(learner: str) -> float:
    from fastai.vision import accuracy
    import dill

    with open(learner, 'rb') as fp:
        learner = dill.load(fp)

    return float(accuracy(*learner.get_preds()).numpy())
def main(epochs):
    Task.init(project_name="examples",
              task_name="fastai with tensorboard callback")

    path = untar_data(URLs.MNIST_SAMPLE)

    data = ImageDataBunch.from_folder(path,
                                      ds_tfms=(rand_pad(2, 28), []),
                                      bs=64,
                                      num_workers=0)
    data.normalize(imagenet_stats)

    learn = cnn_learner(data, models.resnet18, metrics=accuracy)
    tboard_path = Path("data/tensorboard/project1")
    learn.callback_fns.append(
        partial(LearnerTensorboardWriter, base_dir=tboard_path, name="run0"))

    accuracy(*learn.get_preds())
    learn.fit_one_cycle(epochs, 0.01)
Exemple #4
0
    def getaccuracy(self):
        """Returns the accuracy of the model on the test data

        Returns
        -------
        double
            Accuracy
        """
        self.accuracy = accuracy(*(self.learn.get_preds()))
        return self.accuracy
Exemple #5
0
# get the Azure ML run object
run = Run.get_context()

# get images
path = Path('data')
np.random.seed(2)
data = ImageDataBunch.from_folder(path,
                                       train=".",
                                       valid_pct=0.2,
                                       ds_tfms=get_transforms(),
                                       size=224).normalize(imagenet_stats)

# build estimator based on ResNet 34
learn = cnn_learner(data, models.resnet34, metrics=accuracy)
learn.fit_one_cycle(2)

# do test time augmentation and get accuracy
acc = accuracy(*learn.TTA())


# log the accuracy to run
run.log('Accuracy', np.float(acc))
print("Accuracy: ", np.float(acc))

# Save the model to the root. Note: this is not registering model
#learn.path = Path(".")
#learn.export()
#path = learn.path
#path
Exemple #6
0
learn.path = Path(model_save_dir)
learn.model_dir = model_save_dir
learn.metrics = [accuracy]



### START TRAINING
lr=5e-2
learn.fit_one_cycle(12,max_lr = slice(1e-4,lr))

# Unfreeze
learn.unfreeze()
learn.fit(15)
# Refereeze
learn.fit_one_cycle(9,slice(1e-6,1e-3))
tta = accuracy(*learn.TTA()).item()*100
print('Done round 1')
print(tta)


print('Start Round 2')
data_path = '/home/qnkhuat/data/emotion_compilation_split'
tfms = get_transforms(do_flip=True,
                      flip_vert=False,
                      max_rotate=20,
                      max_zoom=1.1,
                     )
# ran this get erro in THcroe
data = (ImageDataBunch.from_folder(data_path,test='test',size=96,ds_tfms=tfms,bs=256).normalize(imagenet_stats))

learn.data = data