Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extra experiment for omniglot and cross_char
- Loading branch information
1 parent
28a219a
commit 31a75f3
Showing
12 changed files
with
320 additions
and
11 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
save_dir = './record/' | ||
save_dir = '/work/newriver/wyharveychen/CloserLookFewShot/' | ||
data_dir = {} | ||
data_dir['CUB'] = './filelists/CUB/' | ||
data_dir['miniImagenet'] = './filelists/miniImagenet/' | ||
data_dir['omniglot'] = './filelists/omniglot/' | ||
data_dir['emnist'] = './filelists/emnist/' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
wget https://github.com/NanqingD/DAOSL/raw/master/data/emnist.zip | ||
unzip emnist.zip | ||
python invert_emnist.py | ||
python write_cross_char_valnovel_filelist.py |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import numpy as np | ||
from os import listdir | ||
from os.path import isfile, isdir, join | ||
import os | ||
import json | ||
import random | ||
from PIL import Image | ||
import PIL.ImageOps | ||
|
||
cwd = os.getcwd() | ||
data_path = join(cwd,'emnist') | ||
inv_data_path = join(cwd,'inv_emnist') | ||
savedir = './' | ||
|
||
#if not os.path.exists(savedir): | ||
# os.makedirs(savedir) | ||
if not os.path.exists(inv_data_path): | ||
os.makedirs(inv_data_path) | ||
|
||
character_folder_list = [str(i) for i in range(62)] #lazy_hack | ||
|
||
classfile_list_all = [] | ||
|
||
for character_folder in character_folder_list: | ||
character_folder_path = join(data_path, character_folder) | ||
inv_character_folder_path = join(inv_data_path, character_folder) | ||
image_list = [ img for img in listdir(character_folder_path) if (isfile(join(character_folder_path,img)) and img[0] != '.')] | ||
if not os.path.exists(inv_character_folder_path): | ||
os.makedirs(inv_character_folder_path) | ||
for img in image_list: | ||
inverted_img =PIL.ImageOps.invert(Image.open(join(character_folder_path,img))) | ||
inverted_img.save(join(inv_character_folder_path ,img)) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import numpy as np | ||
from os import listdir | ||
from os.path import isfile, isdir, join | ||
import os | ||
import json | ||
import random | ||
|
||
cwd = os.getcwd() | ||
data_path = join(cwd,'inv_emnist') | ||
savedir = './' | ||
dataset_list = ['val','novel'] | ||
|
||
#if not os.path.exists(savedir): | ||
# os.makedirs(savedir) | ||
|
||
folder_list = [str(i) for i in range(62)] #lazy_hack | ||
label_dict = dict(zip(folder_list,range(0,len(folder_list)))) | ||
|
||
classfile_list_all = [] | ||
|
||
for i, folder in enumerate(folder_list): | ||
folder_path = join(data_path, folder) | ||
classfile_list_all.append( [ join(folder_path, cf) for cf in listdir(folder_path) if (isfile(join(folder_path,cf)) and cf[0] != '.')]) | ||
random.shuffle(classfile_list_all[i]) | ||
|
||
for dataset in dataset_list: | ||
file_list = [] | ||
label_list = [] | ||
for i, classfile_list in enumerate(classfile_list_all): | ||
if 'val' in dataset: | ||
if (i%2 == 0): | ||
file_list = file_list + classfile_list | ||
label_list = label_list + np.repeat(i, len(classfile_list)).tolist() | ||
if 'novel' in dataset: | ||
if (i%2 == 1): | ||
file_list = file_list + classfile_list | ||
label_list = label_list + np.repeat(i, len(classfile_list)).tolist() | ||
|
||
fo = open(savedir + dataset + ".json", "w") | ||
fo.write('{"label_names": [') | ||
fo.writelines(['"%s",' % item for item in folder_list]) | ||
fo.seek(0, os.SEEK_END) | ||
fo.seek(fo.tell()-1, os.SEEK_SET) | ||
fo.write('],') | ||
|
||
fo.write('"image_names": [') | ||
fo.writelines(['"%s",' % item for item in file_list]) | ||
fo.seek(0, os.SEEK_END) | ||
fo.seek(fo.tell()-1, os.SEEK_SET) | ||
fo.write('],') | ||
|
||
fo.write('"image_labels": [') | ||
fo.writelines(['%d,' % item for item in label_list]) | ||
fo.seek(0, os.SEEK_END) | ||
fo.seek(fo.tell()-1, os.SEEK_SET) | ||
fo.write(']}') | ||
|
||
fo.close() | ||
print("%s -OK" %dataset) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
wget https://raw.githubusercontent.com/jakesnell/prototypical-networks/master/data/omniglot/splits/vinyals/train.txt | ||
wget https://raw.githubusercontent.com/jakesnell/prototypical-networks/master/data/omniglot/splits/vinyals/val.txt | ||
wget https://raw.githubusercontent.com/jakesnell/prototypical-networks/master/data/omniglot/splits/vinyals/test.txt | ||
|
||
DATADIR=./images | ||
mkdir -p $DATADIR | ||
wget -O images_background.zip https://github.com/brendenlake/omniglot/blob/master/python/images_background.zip?raw=true | ||
wget -O images_evaluation.zip https://github.com/brendenlake/omniglot/blob/master/python/images_evaluation.zip?raw=true | ||
unzip images_background.zip -d $DATADIR | ||
unzip images_evaluation.zip -d $DATADIR | ||
mv $DATADIR/images_background/* $DATADIR/ | ||
mv $DATADIR/images_evaluation/* $DATADIR/ | ||
rmdir $DATADIR/images_background | ||
rmdir $DATADIR/images_evaluation | ||
|
||
python rot_omniglot.py | ||
python write_omniglot_filelist.py | ||
python write_cross_char_base_filelist.py |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import numpy as np | ||
from os import listdir | ||
from os.path import isfile, isdir, join | ||
import os | ||
import json | ||
import random | ||
from PIL import Image | ||
|
||
cwd = os.getcwd() | ||
data_path = join(cwd,'images') | ||
savedir = './' | ||
|
||
#if not os.path.exists(savedir): | ||
# os.makedirs(savedir) | ||
|
||
language_folder_list = [f for f in listdir(data_path) if isdir(join(data_path, f))] | ||
language_folder_list.sort() | ||
|
||
classfile_list_all = [] | ||
|
||
for language_folder in language_folder_list: | ||
language_folder_path = join(data_path, language_folder) | ||
character_folder_list = [cf for cf in listdir(language_folder_path) if isdir(join(language_folder_path, cf))] | ||
character_folder_list.sort() | ||
for character_folder in character_folder_list: | ||
character_folder_path = join(language_folder_path, character_folder) | ||
image_list = [ img for img in listdir(character_folder_path) if (isfile(join(character_folder_path,img)) and img[0] != '.')] | ||
for deg in [0,90,180,270]: | ||
rot_str = "rot%03d"%deg | ||
rot_character_path = join(character_folder_path, rot_str) | ||
print(rot_character_path) | ||
if not os.path.exists(rot_character_path): | ||
os.makedirs(rot_character_path) | ||
for img in image_list: | ||
rot_img = Image.open(join(character_folder_path,img)).rotate(deg) | ||
rot_img.save(join(character_folder_path,rot_str,img)) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import numpy as np | ||
from os import listdir | ||
from os.path import isfile, isdir, join | ||
import os | ||
import json | ||
import random | ||
import re | ||
|
||
cwd = os.getcwd() | ||
data_path = join(cwd,'images') | ||
savedir = './' | ||
|
||
#if not os.path.exists(savedir): | ||
# os.makedirs(savedir) | ||
|
||
cl = -1 | ||
folderlist = [] | ||
|
||
language_folder_list = [f for f in listdir(data_path) if isdir(join(data_path, f))] | ||
language_folder_list.sort() | ||
|
||
filelists = {} | ||
|
||
for language_folder in language_folder_list: | ||
if language_folder == 'Latin': | ||
continue | ||
language_folder_path = join(data_path, language_folder) | ||
character_folder_list = [cf for cf in listdir(language_folder_path) if isdir(join(language_folder_path, cf))] | ||
character_folder_list.sort() | ||
for character_folder in character_folder_list: | ||
character_folder_path = join(language_folder_path, character_folder) | ||
label = join(language_folder,character_folder) | ||
folderlist.append(label) | ||
filelists[label] = [ join(character_folder_path,img) for img in listdir(character_folder_path) if (isfile(join(character_folder_path,img)) and img[-3:] == 'png')] | ||
|
||
filelists_flat = [] | ||
labellists_flat = [] | ||
for key, filelist in filelists.items(): | ||
cl += 1 | ||
random.shuffle(filelist) | ||
filelists_flat += filelist | ||
labellists_flat += np.repeat(cl, len(filelist)).tolist() | ||
|
||
fo = open(join(savedir, "noLatin.json"), "w") | ||
fo.write('{"label_names": [') | ||
fo.writelines(['"%s",' % item for item in folderlist]) | ||
fo.seek(0, os.SEEK_END) | ||
fo.seek(fo.tell()-1, os.SEEK_SET) | ||
fo.write('],') | ||
|
||
fo.write('"image_names": [') | ||
fo.writelines(['"%s",' % item for item in filelists_flat]) | ||
fo.seek(0, os.SEEK_END) | ||
fo.seek(fo.tell()-1, os.SEEK_SET) | ||
fo.write('],') | ||
|
||
fo.write('"image_labels": [') | ||
fo.writelines(['%d,' % item for item in labellists_flat]) | ||
fo.seek(0, os.SEEK_END) | ||
fo.seek(fo.tell()-1, os.SEEK_SET) | ||
fo.write(']}') | ||
|
||
fo.close() | ||
print("noLatin -OK") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import numpy as np | ||
from os import listdir | ||
from os.path import isfile, isdir, join | ||
import os | ||
import json | ||
import random | ||
import re | ||
|
||
cwd = os.getcwd() | ||
data_path = join(cwd,'images') | ||
savedir = './' | ||
dataset_list = ['base', 'val', 'novel'] | ||
|
||
#if not os.path.exists(savedir): | ||
# os.makedirs(savedir) | ||
|
||
cl = -1 | ||
folderlist = [] | ||
|
||
datasetmap = {'base':'train','val':'val','novel':'test'}; | ||
filelists = {'base':{},'val':{},'novel':{} } | ||
filelists_flat = {'base':[],'val':[],'novel':[] } | ||
labellists_flat = {'base':[],'val':[],'novel':[] } | ||
|
||
for dataset in dataset_list: | ||
with open(datasetmap[dataset] + ".txt", "r") as lines: | ||
for i, line in enumerate(lines): | ||
label = line.replace('\n','') | ||
folderlist.append(label) | ||
filelists[dataset][label] = [ join(data_path,label, f) for f in listdir( join(data_path, label))] | ||
|
||
for key, filelist in filelists[dataset].items(): | ||
cl += 1 | ||
random.shuffle(filelist) | ||
filelists_flat[dataset] += filelist | ||
labellists_flat[dataset] += np.repeat(cl, len(filelist)).tolist() | ||
|
||
for dataset in dataset_list: | ||
fo = open(savedir + dataset + ".json", "w") | ||
fo.write('{"label_names": [') | ||
fo.writelines(['"%s",' % item for item in folderlist]) | ||
fo.seek(0, os.SEEK_END) | ||
fo.seek(fo.tell()-1, os.SEEK_SET) | ||
fo.write('],') | ||
|
||
fo.write('"image_names": [') | ||
fo.writelines(['"%s",' % item for item in filelists_flat[dataset]]) | ||
fo.seek(0, os.SEEK_END) | ||
fo.seek(fo.tell()-1, os.SEEK_SET) | ||
fo.write('],') | ||
|
||
fo.write('"image_labels": [') | ||
fo.writelines(['%d,' % item for item in labellists_flat[dataset]]) | ||
fo.seek(0, os.SEEK_END) | ||
fo.seek(fo.tell()-1, os.SEEK_SET) | ||
fo.write(']}') | ||
|
||
fo.close() | ||
print("%s -OK" %dataset) |
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
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
Oops, something went wrong.