6. MultiLabel Classification Exploring APIs for Data Preperation
A tutorial for someone have interest we are deep diving to classification Basiaclly we have Explored Datablock ,datasets and lsitzip functionalities.
- Fp16 to fp32 Shit?
- Data Frame Methods
- Book by Creator
- Constructing Data
- DataBlock
- Summary : What I learned about Datablock
- Note
- Lets Give the path of image
PASCAL data set with csv file for labeling and column specify if its validation
pd is for panda
iloc integer location [:,0] -- print all columns
a same as
from fastai.vision.all import *
path = untar_data(URLs.PASCAL_2007)
This dataset is different from the ones we have seen before, in that it is not structured by filename or folder but instead comes with a CSV (comma-separated values) file telling us what labels to use for each image. We can inspect the CSV file by reading it into a Pandas DataFrame:
It will also tell about validation
dataframe is table containing rows and columns
pd.head see first fews
df = pd.read_csv(path/'train.csv')
df.head()
df.iloc[0,:]
# ": " is an option
df.iloc[0]
df.iloc[:,0]
df["fname"]
tmp_df = pd.DataFrame({"a":[1,2],"b":[3,4]})
tmp_df['c'] = tmp_df['a']+ tmp_df['b']
a = list(enumerate(string.ascii_lowercase))
a[0], len(a)
dl_a = DataLoader(a, batch_size =8,shuffle=True)
first(dl_a)
list(zip(first(dl_a)))
b=first(dl_a)
list(zip(b[0],b[1]))
list(zip(*b))
a = list(string.ascii_lowercase)
a[0],len(a)
dss = Datasets(a)
dss[0]
def f1(o): return o+"a"
def f2(o): return o+"b"
dss = Datasets(a, [[f1]])
dss[0]
dss = Datasets(a, [[f1,f2]])
dss[0]
dss = Datasets(a,[[f1],[f2]])
dss[0]
dls = DataLoaders.from_dsets(dss,batch_size =4)
first(dls.train)
dblock = DataBlock()
dsets = dblock.datasets(df)
len(dsets.train),len(dsets.valid)
first row is shuffled by default datablock assumed we have two things input and target train and valid =20 percent
x,y = dsets.train[0]
x,y
independent varable and dependent check
x["fname"]
Summary : What I learned about Datablock
- Configure your dataset methods label and traning etc
- call dataset function that will handle it
what if i will call dataloaders
Recall in image case we did
pets = Datablock (specify everything how labels to get from filename ,get_y etc...)
pets.dataloaders(image path)
dblock = DataBlock(get_x = lambda r: r["fname"],get_y = lambda r: r["labels"])
dsets = dblock.datasets(df)
dsets.train[0]
def get_x(r): return r['fname']
def get_y(r): return r['labels']
dblock = DataBlock(get_x = get_x, get_y = get_y)
dsets = dblock.datasets(df)
dsets.train[0]
Path.BASE_PATH = path
def get_x(r): return path/'train'/r['fname']
def get_y(r): return r['labels'].split(' ')
dblock = DataBlock(get_x = get_x, get_y = get_y)
dsets = dblock.datasets(df)
dsets.train[0]
dblock = DataBlock(blocks =(ImageBlock,MultiCategoryBlock),
get_x=get_x,get_y=get_y)
dsets =dblock.datasets(df)
dsets.train[0]