Skip to content

Instantly share code, notes, and snippets.

@dvschultz
Last active November 13, 2020 07:10
Show Gist options
  • Save dvschultz/ed01a2a53e99927a87d789064a642d32 to your computer and use it in GitHub Desktop.
Save dvschultz/ed01a2a53e99927a87d789064a642d32 to your computer and use it in GitHub Desktop.
import numpy as np
import scipy.ndimage as nd
import tensorflow as tf
from PIL import Image
import lucid.modelzoo.vision_models as models
from lucid.misc.io import show
import lucid.optvis.objectives as objectives
import lucid.optvis.param as param
import lucid.optvis.render as render
import lucid.optvis.transform as transform
model = models.InceptionV1()
model.load_graphdef()
def interpolate_param_f():
unique = param.fft_image((60, 128, 128, 3))
shared = [
param.lowres_tensor((60, 128, 128, 3), (1, 128//1, 128//1, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//2, 128//2, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//3, 128//3, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//4, 128//4, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//5, 128//5, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//6, 128//6, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//7, 128//7, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//8, 128//8, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//9, 128//9, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//10, 128//10, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//11, 128//11, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//12, 128//12, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//13, 128//13, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//14, 128//14, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//15, 128//15, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//16, 128//16, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//17, 128//17, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//18, 128//18, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//19, 128//19, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//20, 128//20, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//21, 128//21, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//22, 128//22, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//23, 128//23, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//24, 128//24, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//25, 128//25, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//26, 128//26, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//27, 128//27, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//28, 128//28, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//29, 128//29, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//30, 128//30, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//31, 128//31, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//32, 128//32, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//33, 128//33, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//34, 128//34, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//35, 128//35, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//36, 128//36, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//37, 128//37, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//38, 128//38, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//39, 128//39, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//40, 128//40, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//41, 128//41, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//42, 128//42, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//43, 128//43, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//44, 128//44, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//45, 128//45, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//46, 128//46, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//47, 128//47, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//48, 128//48, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//49, 128//49, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//50, 128//50, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//51, 128//51, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//52, 128//52, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//53, 128//53, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//54, 128//54, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//55, 128//55, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//56, 128//56, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//57, 128//57, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//58, 128//58, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//59, 128//59, 3)),
param.lowres_tensor((60, 128, 128, 3), (1, 128//60, 128//60, 3)),
]
return param.to_valid_rgb(unique + sum(shared), decorrelate=True)
obj = objectives.channel_interpolate("mixed4a_pre_relu", 476, "mixed4b_pre_relu", 111)
_ = render.render_vis(model, obj, interpolate_param_f, use_fixed_seed=True)[-1][0]
Image.fromarray(np.uint8(_*255)).save("img1.png")
obj = objectives.channel_interpolate("mixed4b_pre_relu", 111, "mixed4a_pre_relu", 476)
_ = render.render_vis(model, obj, interpolate_param_f, use_fixed_seed=True)[-1][0]
Image.fromarray(np.uint8(_*255)).save("img2.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment