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...
共计 109 篇文章,14 页。