# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd
import numpy as numpy
import os
import re

label_df = pd.read_csv('flower_natural_with_label2.csv', index_col=0) 

pres = list(label_df['pre'].unique())
pres[:10]

l = ! ls flower/images

# +
# # os.makedirs("flower_drop/images")
# for fname in l:
#     pre = re.findall('(.+)_', fname)[0]
#     if pre in pres:
#         shutil.move("flower/images/"+fname, "flower_drop/images/"+fname)
# -

# fnames = !ls flower_drop/images
df = pd.DataFrame(fnames)
df[1] = [re.findall('(.+)_', fname)[0] for fname in fnames]
df[2] = [int(re.findall('_(\d+).png', fname)[0]) % 2 for fname in fnames]
df.columns = ['fname', 'pre', 'label']
idxs = list(df.index)
labels = df['label']
pres = df['pre'].unique()
df

len(unique)

from sklearn.model_selection import train_test_split
pre_train, pre_test = train_test_split(pres, random_state=0)

sorted(pre_train)

# +
pres_list = list(df['pre'])

tr_ts = ['ts' if pre in pre_test else 'tr' for pre in pres_list]
df['tr/ts'] = tr_ts
# -

label_df['label'] = [0 if label == 'r' else 1 for label in label_df['label']]
label_df

pres_lst = label_df['pre']

# +
trts = ['ts' if pre in pre_test else 'tr' for pre in pres_lst]

label_df['tr/ts'] = trts
# -

label_df[label_df['pre'] == '94']

df.to_csv('support_set.csv', index = False)
label_df.to_csv('query_set.csv', index = False)

len(pres)

print(list(label_df[label_df['tr/ts'] == 'tr']['label'] == 0).count(True))
print(list(label_df[label_df['tr/ts'] == 'tr']['label'] == 1).count(True))

label_df.groupby(['label', 'tr/ts']).count()['fname']
589 + 197 + 593 + 198
395 + 1182

import shutil
# l = !ls ../MAML-Pytorch_copy4/flower_natural2/images
os.makedirs("../MAML-Pytorch_copy4/flower_natural2_drop/images")
for fname in l:
    if fname in fnames:
        shutil.move("../MAML-Pytorch_copy4/flower_natural2/images/"+fname, "../MAML-Pytorch_copy4/flower_natural2_drop/images/"+fname)

pre_val_, pre_test_ = train_test_split(pre_test, random_state=0, train_size = 0.5)

len(pre_test)

len(pre_train)

len(pre_val_), len(pre_test_)

# +
dic = []
for pre in pre_train:
    dic.append((pre, 'tr'))
for pre in pre_test_:
    dic.append((pre, 'ts'))
for pre in pre_val_:
    dic.append((pre, 'val'))
dic = dict(dic)

df_ = df

df_['tr/ts/val'] = [dic[pre] for pre in df['pre']]

df_.groupby('tr/ts/val').count()['fname']

df_.to_csv('support_set_tr_ts_val.csv', index = False)

# +
dic_label = []
for pre in pre_train:
    dic_label.append((pre, 'tr'))
for pre in pre_test_:
    dic_label.append((pre, 'ts'))
for pre in pre_val_:
    dic_label.append((pre, 'val'))
dic_label = dict(dic_label)

label_df_ = label_df

label_df_['tr/ts/val'] = [dic_label[pre] for pre in label_df['pre']]

print(label_df_.groupby('tr/ts/val').count()['fname'])

label_df_.to_csv('query_set_tr_ts_val.csv', index = False)
# -



# +
import numpy as np
with open('data/acc/natural2(task_num_10).txt') as f:
    l = f.readlines()
#     print(l)

l_ = [float(re.findall('(.+)\n', p)[0]) for p in l]

np.array(l_).mean(), np.array(l_).std()

# +
import numpy as np
with open('data/acc/natural2(task_num_5).txt') as f:
    l = f.readlines()
#     print(l)

l_ = [float(re.findall('(.+)\n', p)[0]) for p in l]

np.array(l_).mean(), np.array(l_).std()

# +
import numpy as np
with open('data/acc/natural2(task_num_50).txt') as f:
    l = f.readlines()
#     print(l)

l_ = [float(re.findall('(.+)\n', p)[0]) for p in l]

np.array(l_).mean(), np.array(l_).std()

# +
import numpy as np
with open('data/acc/natural2(task_num_100).txt') as f:
    l = f.readlines()
#     print(l)

l_ = [float(re.findall('(.+)\n', p)[0]) for p in l]

np.array(l_).mean(), np.array(l_).std()

# +
import re
import numpy as np
with open('data/acc/natural2_test(task_num_5).txt') as f:
    l = f.readlines()
#     print(l)

l_ = [float(re.findall('(.+)\n', p)[0]) for p in l]

np.array(l_).mean(), np.array(l_).std(), np.array(l_).max()

format(np.array(l_).mean(), '.3f'), format(np.array(l_).std(), '.3f'), format(np.array(l_).max(), '.3f')

# +
import re
import numpy as np
with open('data/acc/natural2_test(task_num_5).txt') as f:
    l = f.readlines()
#     print(l)

l_ = [float(re.findall('(.+)\n', p)[0]) for p in l]

np.array(l_).mean(), np.array(l_).std(), np.array(l_).max()

format(np.array(l_).mean(), '.3f'), format(np.array(l_).std(), '.3f'), format(np.array(l_).max(), '.3f')

# +
import re
import numpy as np
with open('data/acc/natural2_val(task_num_5epoch_num_30000).txt') as f:
    l = f.readlines()
#     print(l)

l_ = [float(re.findall('(.+)\n', p)[0]) for p in l]

np.array(l_).mean(), np.array(l_).std(), np.array(l_).max()

format(np.array(l_).mean(), '.3f'), format(np.array(l_).std(), '.3f'), format(np.array(l_).max(), '.3f')

# +
import re
import numpy as np
with open('data/acc/natural2_val(task_num_5epoch_num_40000).txt') as f:
    l = f.readlines()
#     print(l)

l_ = [float(re.findall('(.+)\n', p)[0]) for p in l]

np.array(l_).mean(), np.array(l_).std(), np.array(l_).max()

format(np.array(l_).mean(), '.3f'), format(np.array(l_).std(), '.3f'), format(np.array(l_).max(), '.3f')
# -

# !pwd



StarcoderdataJupyterScriptsDedupFiltered