Created
October 7, 2023 13:08
-
-
Save briansp2020/92c56be60caeb2e497eaa275b85e13fb to your computer and use it in GitHub Desktop.
fastai example code
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 fastai.vision.all import * | |
from fastai.text.all import * | |
from fastai.collab import * | |
from fastai.tabular.all import * | |
path = untar_data(URLs.PETS)/'images' | |
def is_cat(x): return x[0].isupper() | |
dls = ImageDataLoaders.from_name_func( | |
path, get_image_files(path), valid_pct=0.2, seed=42, | |
label_func=is_cat, item_tfms=Resize(224)) | |
learn = vision_learner(dls, convnext_small, metrics=error_rate) | |
learn.fine_tune(1) | |
print("Training text processing model") | |
dls = TextDataLoaders.from_folder(untar_data(URLs.IMDB), valid='test') | |
learn = text_classifier_learner(dls, AWD_LSTM, drop_mult=0.5, metrics=accuracy) | |
learn.fine_tune(2, 1e-2) | |
learn.predict("I really liked that movie!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment