Created
July 8, 2017 09:42
-
-
Save cwgreene/6c000e9b78b19c62e78806451e4c90be to your computer and use it in GitHub Desktop.
The solution
This file contains hidden or 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
# Initiate our vector | |
auto_next = scipy.misc.imread("starting_file_that_is_32x32x3.png") | |
# create the thing that pokes in the dx_i direction | |
def dxi(i,j,k): | |
a = np.zeros(shape=(32,32,3)) | |
a[i][j][k] = 1 | |
return a | |
# Create an array of all possible directions to poke in | |
dxis = np.array([dxi(i,j,k) for i in range(32) for j in range(32) for k in range(3)]) | |
# do a step | |
def step(auto): | |
print model.predict(np.array([auto]))[0][1] | |
# Find the (orthogonal) direction that makes the biggest change | |
biggest = max([(a[1], i) for (i,a) in enumerate((model.predict(auto+dxis)-model.predict((auto+dxis)-dxis)))]) | |
print biggest | |
# step in that direction | |
auto_next = auto + 10*dxis[biggest[1]] | |
return auto_next | |
while True: | |
auto_next = step(auto_next) | |
print model.predict(np.array([auto_next])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is of course an insane way to do this. I'm almost positive that keras provides some way for me to compute the gradient on the layers, I was just too tired to figure it out at the time.