forked from mrq/DL-Art-School
Misc changes
This commit is contained in:
parent
9fc3df3f5b
commit
94e069bced
|
@ -55,9 +55,9 @@ def im_norm(x):
|
||||||
def get_image_folder_dataloader(batch_size, num_workers, target_size=224, shuffle=True):
|
def get_image_folder_dataloader(batch_size, num_workers, target_size=224, shuffle=True):
|
||||||
dataset_opt = dict_to_nonedict({
|
dataset_opt = dict_to_nonedict({
|
||||||
'name': 'amalgam',
|
'name': 'amalgam',
|
||||||
'paths': ['F:\\4k6k\\datasets\\ns_images\\imagesets\\pn_coven\\cropped2'],
|
#'paths': ['F:\\4k6k\\datasets\\ns_images\\imagesets\\pn_coven\\cropped2'],
|
||||||
#'paths': ['F:\\4k6k\\datasets\\ns_images\\imagesets\\imageset_1024_square_with_new'],
|
#'paths': ['F:\\4k6k\\datasets\\ns_images\\imagesets\\imageset_1024_square_with_new'],
|
||||||
#'paths': ['F:\\4k6k\\datasets\\ns_images\\imagesets\\imageset_256_full'],
|
'paths': ['F:\\4k6k\\datasets\\ns_images\\imagesets\\imageset_256_tiled_filtered_flattened'],
|
||||||
#'paths': ['F:\\4k6k\\datasets\\ns_images\\imagesets\\1024_test'],
|
#'paths': ['F:\\4k6k\\datasets\\ns_images\\imagesets\\1024_test'],
|
||||||
'weights': [1],
|
'weights': [1],
|
||||||
'target_size': target_size,
|
'target_size': target_size,
|
||||||
|
@ -100,6 +100,7 @@ def get_latent_for_img(model, img):
|
||||||
img_t = img_t[:, :, :, dw:-dw]
|
img_t = img_t[:, :, :, dw:-dw]
|
||||||
elif dh != 0:
|
elif dh != 0:
|
||||||
img_t = img_t[:, :, dh:-dh, :]
|
img_t = img_t[:, :, dh:-dh, :]
|
||||||
|
img_t = img_t[:,:3,:,:]
|
||||||
img_t = torch.nn.functional.interpolate(img_t, size=(224, 224), mode="area")
|
img_t = torch.nn.functional.interpolate(img_t, size=(224, 224), mode="area")
|
||||||
model(img_t)
|
model(img_t)
|
||||||
latent = layer_hooked_value
|
latent = layer_hooked_value
|
||||||
|
@ -129,14 +130,14 @@ def produce_latent_dict(model):
|
||||||
def find_similar_latents(model, compare_fn=structural_euc_dist):
|
def find_similar_latents(model, compare_fn=structural_euc_dist):
|
||||||
global layer_hooked_value
|
global layer_hooked_value
|
||||||
|
|
||||||
img = 'F:\\4k6k\\datasets\\ns_images\\imagesets\\1024_test\\80692045.jpg.jpg'
|
img = 'D:\\dlas\\results\\bobz.png'
|
||||||
#img = 'F:\\4k6k\\datasets\\ns_images\\adrianna\\analyze\\analyze_xx\\nicky_xx.jpg'
|
#img = 'F:\\4k6k\\datasets\\ns_images\\adrianna\\analyze\\analyze_xx\\nicky_xx.jpg'
|
||||||
output_path = '../../../results/byol_resnet_similars'
|
output_path = '../../../results/byol_resnet_similars'
|
||||||
os.makedirs(output_path, exist_ok=True)
|
os.makedirs(output_path, exist_ok=True)
|
||||||
imglatent = get_latent_for_img(model, img).squeeze().unsqueeze(0)
|
imglatent = get_latent_for_img(model, img).squeeze().unsqueeze(0)
|
||||||
_, c = imglatent.shape
|
_, c = imglatent.shape
|
||||||
|
|
||||||
batch_size = 128
|
batch_size = 512
|
||||||
num_workers = 8
|
num_workers = 8
|
||||||
dataloader = get_image_folder_dataloader(batch_size, num_workers)
|
dataloader = get_image_folder_dataloader(batch_size, num_workers)
|
||||||
id = 0
|
id = 0
|
||||||
|
@ -152,7 +153,7 @@ def find_similar_latents(model, compare_fn=structural_euc_dist):
|
||||||
result_paths.extend(batch['HQ_path'])
|
result_paths.extend(batch['HQ_path'])
|
||||||
id += batch_size
|
id += batch_size
|
||||||
if id > 10000:
|
if id > 10000:
|
||||||
k = 500
|
k = 200
|
||||||
results = torch.cat(results, dim=0)
|
results = torch.cat(results, dim=0)
|
||||||
vals, inds = torch.topk(results, k, largest=False)
|
vals, inds = torch.topk(results, k, largest=False)
|
||||||
for i in inds:
|
for i in inds:
|
||||||
|
@ -201,7 +202,7 @@ if __name__ == '__main__':
|
||||||
register_hook(model, 'avgpool')
|
register_hook(model, 'avgpool')
|
||||||
|
|
||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
#find_similar_latents(model, structural_euc_dist)
|
find_similar_latents(model, structural_euc_dist)
|
||||||
#produce_latent_dict(model)
|
#produce_latent_dict(model)
|
||||||
#build_kmeans()
|
#build_kmeans()
|
||||||
use_kmeans()
|
#use_kmeans()
|
||||||
|
|
|
@ -19,8 +19,8 @@ def main():
|
||||||
# compression time. If read raw images during training, use 0 for faster IO speed.
|
# compression time. If read raw images during training, use 0 for faster IO speed.
|
||||||
|
|
||||||
opt['dest'] = 'file'
|
opt['dest'] = 'file'
|
||||||
opt['input_folder'] = ['F:\\4k6k\\datasets\\images\\lsun\\lsun\\cats']
|
opt['input_folder'] = ['E:\\4k6k\\datasets\\images\\faces\\CelebAMask-HQ\\CelebA-HQ-img']
|
||||||
opt['save_folder'] = 'F:\\4k6k\\datasets\\images\\lsun\\lsun\\cats\\cropped'
|
opt['save_folder'] = 'E:\\4k6k\\datasets\\images\\faces\\CelebAMask-HQ\\256px'
|
||||||
opt['imgsize'] = 256
|
opt['imgsize'] = 256
|
||||||
opt['bottom_crop'] = 0
|
opt['bottom_crop'] = 0
|
||||||
opt['keep_folder'] = False
|
opt['keep_folder'] = False
|
||||||
|
|
Loading…
Reference in New Issue
Block a user