主页

fastai notebook - tabular

soruce Tabular training from fastai.tabular.all import * path = untar_data(URLs.ADULT_SAMPLE) path.ls() df = pd.read_csv(path/'adult.csv') df.head() dls = TabularDataLoaders.from_csv(path/'adult.csv', path=path, y_names="salary", cat_names = ['workclass', 'education', 'marital-status', 'occupation', 'relationship', 'race'], cont_names...

阅读更多

fastai notebook - other

soruce fine-tune Fine-tuning: A transfer learning technique where the parameters of a pretrained model are updated by training for additional epochs using a different task to that used for pretraining. When you use the fine_tune method, fastai will use these tricks for you. There are a few parameters you can set (which we’ll discuss later), bu...

阅读更多

fastai notebook - mid tier api

soruce Transform from fastai.text.all import * from fastai.vision.all import * source = untar_data(URLs.MNIST_TINY)/'train' items = get_image_files(source) fn = items[0]; fn img = PILImage.create(fn); img tconv = ToTensor() img = tconv(img) img.shape,type(img) lbl = parent_label(fn); lbl tcat = Categorize(vocab=['3','7']) lbl = tcat(lbl); l...

阅读更多

fastai notebook - loading data and training

soruce Loading the data with a factory method from fastai.vision.all import * path = untar_data(URLs.IMAGENETTE_160) dls = ImageDataLoaders.from_folder(path, valid='val', item_tfms=RandomResizedCrop(128, min_scale=0.35), batch_tfms=Normalize.from_stats(*imagenet_stats)) dls.show_batch() Loading the data with the data block API fnames = ...

阅读更多

fastai notebook - datablock

soruce Building a DataBlock from scratch from fastai.data.all import * from fastai.vision.all import * path = untar_data(URLs.PETS) fnames = get_image_files(path/"images") dblock = DataBlock() dsets = dblock.datasets(fnames) dsets.train[0] > (Path('/home/jhoward/.fastai/data/oxford-iiit-pet/images/Birman_82.jpg'), Path('/home/jhoward/....

阅读更多

fastai notebook - custom transform

soruce Text transfer learning from fastai.text.all import * from fastai.vision.all import * # !pip install albumentations source = untar_data(URLs.PETS) items = get_image_files(source/"images") class AlbumentationsTransform(Transform): def __init__(self, aug): self.aug = aug def encodes(self, img: PILImage): aug_img = self.aug...

阅读更多

fastai notebook - Collaborative

soruce Text transfer learning from fastai.tabular.all import * from fastai.collab import * path = untar_data(URLs.ML_100k) # The main table is in u.data. Since it’s not a proper csv, we have to specify a few things while opening it: the tab delimiter, the columns we want to keep and their names. ratings = pd.read_csv(path/'u.data', delimiter=...

阅读更多

pathlib

soruce pathlib >>> from pathlib import * >>> p =Path(".") >>> [x for x in p.iterdir() if x.is_dir()] [PosixPath('test1'), PosixPath('test2')] # glob >>> list(p.glob('**/*.py')) [PosixPath('test.py'), PosixPath('test2/p1.py'), PosixPath('test2/test21/p3.py'), PosixPath('test2/test21/p2.py')] >>> lis...

阅读更多