コード例 #1
0
autoencoder = keras.models.Model(inputs=inp, outputs=reconstruction)
autoencoder.compile(optimizer="adamax", loss='mse')

print(autoencoder.evaluate(X_test, X_test, verbose=0))
print(reconstruction_mse)

"""# Submit to Coursera"""

from submit import submit_autoencoder
submission = build_deep_autoencoder(IMG_SHAPE, code_size=71)

# token expires every 30 min
COURSERA_TOKEN = "uhndbT92FI2cDQ95"
COURSERA_EMAIL = "*****@*****.**"

submit_autoencoder(submission, reconstruction_mse, COURSERA_EMAIL, COURSERA_TOKEN)

"""# Optional: Denoising Autoencoder

This part is **optional**, it shows you one useful application of autoencoders: denoising. You can run this code and make sure denoising works :) 

Let's now turn our model into a denoising autoencoder:
<img src="https://github.com/hse-aml/intro-to-dl/blob/master/week4/images/denoising.jpg?raw=1" style="width:40%">

We'll keep the model architecture, but change the way it is trained. In particular, we'll corrupt its input data randomly with noise before each epoch.

There are many strategies to introduce noise: adding gaussian white noise, occluding with random black rectangles, etc. We will add gaussian white noise.
"""

def apply_gaussian_noise(X,sigma=0.1):
    """
コード例 #2
0
autoencoder.compile(optimizer="adamax", loss='mse')

print(autoencoder.evaluate(X_test, X_test, verbose=0))
print(reconstruction_mse)


# # Submit to Coursera

# In[ ]:

from submit import submit_autoencoder
submission = build_deep_autoencoder(IMG_SHAPE, code_size=71)

# token expires every 30 min
COURSERA_TOKEN = ### YOUR TOKEN HERE
COURSERA_EMAIL = ### YOUR EMAIL HERE

submit_autoencoder(submission, reconstruction_mse, COURSERA_EMAIL, COURSERA_TOKEN)


# # Optional: Denoising Autoencoder
# 
# This part is **optional**, it shows you one useful application of autoencoders: denoising. You can run this code and make sure denoising works :) 
# 
# Let's now turn our model into a denoising autoencoder:
# <img src="images/denoising.jpg" style="width:40%">
# 
# We'll keep the model architecture, but change the way it is trained. In particular, we'll corrupt its input data randomly with noise before each epoch.
# 
# There are many strategies to introduce noise: adding gaussian white noise, occluding with random black rectangles, etc. We will add gaussian white noise.

# In[ ]:
コード例 #3
0
    visualize(img,encoder,decoder)


# In[25]:

encoder.save("./encoder.h5")
decoder.save("./decoder.h5")


# ### Submit to Coursera

# In[28]:

from submit import submit_autoencoder
submission = build_deep_autoencoder(img_shape,code_size=71)
submit_autoencoder(submission, reconstruction_mse, "*****@*****.**", "Hj9Wv8DXrLFcJyDS")


# ### Image retrieval with autoencoders
# 
# So we've just trained a network that converts image into itself imperfectly. This task is not that useful in and of itself, but it has a number of awesome side-effects. Let's see it in action.
# 
# First thing we can do is image retrieval aka image search. We we give it an image and find similar images in latent space. 
# 
# To speed up retrieval process, we shall use Locality-Sensitive Hashing on top of encoded vectors. We'll use scikit-learn's implementation for simplicity. In practical scenario, you may want to use [specialized libraries](https://erikbern.com/2015/07/04/benchmark-of-approximate-nearest-neighbor-libraries.html) for better performance and customization.

# In[ ]:

images = X_train
codes = <encode all images>
assert len(codes) == len(images)
autoencoder = keras.models.Model(inputs=inp, outputs=reconstruction)
autoencoder.compile(optimizer="adamax", loss='mse')

print(autoencoder.evaluate(X_test, X_test, verbose=0))
print(reconstruction_mse)

"""# Submit to Coursera"""

from submit import submit_autoencoder
submission = build_deep_autoencoder(IMG_SHAPE, code_size=71)

# token expires every 30 min
COURSERA_TOKEN = '**************' ### YOUR TOKEN HERE
COURSERA_EMAIL ='d*************[email protected]' ### YOUR EMAIL HERE

submit_autoencoder(submission, '0.005503223562159863', COURSERA_EMAIL, COURSERA_TOKEN)

"""# Optional: Denoising Autoencoder

This part is **optional**, it shows you one useful application of autoencoders: denoising. You can run this code and make sure denoising works :) 

Let's now turn our model into a denoising autoencoder:
<img src="https://github.com/hse-aml/intro-to-dl/blob/master/week4/images/denoising.jpg?raw=1" style="width:40%">

We'll keep the model architecture, but change the way it is trained. In particular, we'll corrupt its input data randomly with noise before each epoch.

There are many strategies to introduce noise: adding gaussian white noise, occluding with random black rectangles, etc. We will add gaussian white noise.
"""

def apply_gaussian_noise(X,sigma=0.1):
    """