<jupyter_start><jupyter_text>1st notebook run<jupyter_code>from fastai.vision.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 = cnn_learner(dls, resnet34, metrics=error_rate)
learn.fine_tune(1)<jupyter_output>/home/industark/anaconda3/lib/python3.8/site-packages/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: The NVIDIA driver on your system is too old (found version 9010). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver. (Triggered internally at  ../c10/cuda/CUDAFunctions.cpp:115.)
  return torch._C._cuda_getDeviceCount() > 0<jupyter_text>Widgets<jupyter_code>import ipywidgets as widgets
uploader = widgets.FileUpload()
uploader
uploader = SimpleNamespace(data = ['img/001_pic.jpg'])
img = PILImage.create(uploader.data[0])
is_cat,_,probs = learn.predict(img)

print(f"Is this a cat?: {is_cat}.")
print(f"Probability it's a cat: {probs[1].item():.6f}")
uploader2 = SimpleNamespace(data = ['img/002_pic.jpg'])
img2 = PILImage.create(uploader2.data[0])
is_cat,_,probs = learn.predict(img2)

print(f"Is this a cat?: {is_cat}.")
print(f"Probability it's a cat: {probs[1].item():.6f}")
learn.show_results(max_n=6, figsize=(7,8))<jupyter_output><empty_output><jupyter_text>Segmentation example<jupyter_code>path_seg = untar_data(URLs.CAMVID_TINY)

learn_dataset_seg = SegmentationDataLoaders.from_label_func(
    path_seg, bs=8, fnames = get_image_files(path_seg/"images"),
    label_func = lambda o: path_seg/'labels'/f'{o.stem}_P{o.suffix}',
    codes = np.loadtxt(path_seg/'codes.txt', dtype=str)
    )

learn_seg = unet_learner(learn_dataset_seg, resnet34)
learn_seg.fine_tune(8)
learn_seg.show_results(max_n=4, figsize=(16,20))<jupyter_output><empty_output><jupyter_text>Text data prediction - NLP<jupyter_code>from fastai.text.all import *

path_txt = untar_data(URLs.IMDB)

learn_dataset_txt = TextDataLoaders.from_folder(path_txt, valid='test', bs=32)

learn_txt = text_classifier_learner(learn_dataset_txt, AWD_LSTM, drop_mult=0.5, metrics=accuracy)
learn_txt.fine_tune(2, 1e-1)
learn_txt.predict("I really liked that movie!")<jupyter_output><empty_output><jupyter_text>Tabular Data<jupyter_code>from fastai.tabular.all import *

path_tab = untar_data(URLs.ADULT_SAMPLE)

dls_tab = TabularDataLoaders.from_csv(path_tab/'adult.csv', path=path_tab, y_names="salary",
    cat_names = ['workclass', 'education', 'marital-status', 'occupation',
                 'relationship', 'race'],
    cont_names = ['age', 'fnlwgt', 'education-num'],
    procs = [Categorify, FillMissing, Normalize])

learn_tab = tabular_learner(dls_tab, metrics=accuracy)
learn_tab.fit_one_cycle(3)<jupyter_output><empty_output><jupyter_text>Collab<jupyter_code>from fastai.collab import *

path_col = untar_data(URLs.ML_SAMPLE)

dls_col = CollabDataLoaders.from_csv(path_col/'ratings.csv')
learn_col = collab_learner(dls_col, y_range=(0.5,5.5))
learn_col.fine_tune(10)
learn_col.show_results()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13459801264679314, 'fraction_numerical': 0.02077687443541102, 'mean_word_length': 7.043583535108959, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '126952', 'license': 'MIT', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1280, 'n_words': 207, 'path': 'Courses/course.fast.ai/Notebooks/01_intro.ipynb', 'repo_name': 'industArk/AI_learn', 'size': '3321'}