Last active
April 10, 2019 08:49
-
-
Save none53/848f3906d1e1e20acdc3000f7b6a3f38 to your computer and use it in GitHub Desktop.
fastai split_by idxs
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
#その3 | |
#fastai/fastai/vision/data.py | |
''' | |
data = ImageDataBunch.from_csv(path, ds_tfms=tfms, size=128) | |
print(data) | |
''' | |
''' | |
@classmethod | |
def from_csv(cls, path:PathOrStr, folder:PathOrStr=None, label_delim:str=None, csv_labels:PathOrStr='labels.csv', | |
valid_pct:float=0.2, fn_col:int=0, label_col:int=1, suffix:str='', delimiter:str=None, | |
header:Optional[Union[int,str]]='infer', **kwargs:Any)->'ImageDataBunch': | |
"Create from a csv file in `path/csv_labels`." | |
path = Path(path) | |
df = pd.read_csv(path/csv_labels, header=header, delimiter=delimiter) | |
return cls.from_df(path, df, folder=folder, label_delim=label_delim, valid_pct=valid_pct, | |
fn_col=fn_col, label_col=label_col, suffix=suffix, **kwargs) | |
''' | |
''' | |
path2 = Path(path) | |
df = pd.read_csv(path2/csv_labels, header=header, delimiter=delimiter) | |
data2 = ImageDataBunch.from_df( | |
path2, df, folder=folder, | |
label_delim=label_delim, | |
valid_pct=valid_pct, | |
fn_col=fn_col, | |
label_col=label_col, | |
suffix=suffix) | |
print(data2) | |
''' | |
''' | |
@classmethod | |
def from_df(cls, path:PathOrStr, df:pd.DataFrame, folder:PathOrStr=None, label_delim:str=None, valid_pct:float=0.2, | |
fn_col:IntsOrStrs=0, label_col:IntsOrStrs=1, suffix:str='', **kwargs:Any)->'ImageDataBunch': | |
"Create from a `DataFrame` `df`." | |
''' | |
folder = None | |
label_delim = None | |
csv_labels = 'labels.csv' | |
valid_pct = 0.2 | |
fn_col = 0 | |
label_col = 1 | |
suffix = '' | |
delimiter = None | |
header ='infer' | |
path2 = Path(path) | |
df = pd.read_csv(path2/csv_labels, header=header, delimiter=delimiter) | |
''' | |
src = (ImageList.from_df(df, path=path, folder=folder, suffix=suffix, cols=fn_col) | |
.split_by_rand_pct(valid_pct) | |
.label_from_df(label_delim=label_delim, cols=label_col)) | |
''' | |
src1 = ImageList.from_df(df, path=path, folder=folder, suffix=suffix, cols=fn_col) | |
print(src1) | |
train_idx = list(range(100,1000)) | |
valid_idx = list(range(2000,)) | |
src2 = src1.split_by_idxs(train_idx, valid_idx) | |
#src2 = src1.split_by_rand_pct(valid_pct) | |
#src3 = src2.label_from_df(label_delim=label_delim, cols=label_col) | |
#ImageDataBunch.create_from_ll(src3) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment