Ejemplo n.º 1
0
# plt.imshow(im[:,:,3])
# plt.show()

begin_training = raw_input("Press enter to begin traning: ")

import datetime
print(datetime.datetime.now())

from deeplens.resnet_classifier import deeplens_classifier
print 'Training begining...'
print str(n_epochs) + ' epochs...'
print str(imgs) + ' images...'

model = deeplens_classifier(learning_rate=0.001,
                            learning_rate_steps=3,
                            learning_rate_drop=0.1,
                            batch_size=128,
                            n_epochs=n_epochs)

model.fit(x, y, xval, yval)

model.save('deeplens_params_final.npy')

model.eval_purity_completeness(xval, yval)

tpr, fpr, th = model.eval_ROC(xval, yval)

plt.title('ROC on Training set')
plt.plot(fpr, tpr)
plt.xlabel('FPR')
plt.ylabel('TPR')
from __future__ import print_function  #, division
import sys
sys.path.append('..')
import time
from astropy.table import Table
import pyfits as fits
import numpy as np
import matplotlib.pyplot as plt
from os.path import expanduser
from deeplens.resnet_classifier import deeplens_classifier
home = expanduser("~")

user_imgs = raw_input("please input the number of origional training images: ")
orig_epoch = raw_input("please input the number of origional epochs: ")

model = deeplens_classifier()

imgs = int(user_imgs)

# download_path=home+'/Desktop/'
download_path = '//Volumes/CJSTORFER/'

export_path = home + '/Desktop/'  # To be adjusted on your machine

d = Table.read(export_path + 'catalogs_' + str(imgs) + '_RGB.hdf5',
               path='/ground')  # Path to be adjusted on your machine

x = np.asarray(d['image']).reshape((-1, 3, 101, 101))
# print x.shape

y = np.asarray(d['is_lens']).reshape((-1, 1))
# Check that the path to the deeplens.resnet_classifier is set correctly on your machine, should you wish to run this notebook

from deeplens.resnet_classifier import deeplens_classifier
# reload(sys.modules['deeplens.resnet_classifier'])



# Below are the fiducial rates I ran for 2,000 images. These hyper-parameters need to be adjusted.
# If the RNN does not converge, try lowering the learning_rate / learning_rate_drop
# Also try adjusting bach_size
# Adjusting n_epochs can help you converge, i.e. number of passes through the whole training set

model = deeplens_classifier(learning_rate=0.0001,  # Initial learning rate
                          learning_rate_steps=3,  # Number of learning rate updates during training
                          learning_rate_drop=0.001, # Amount by which the learning rate is updated
                          batch_size=128,         # Size of the mini-batch
                          n_epochs=50)           # Number of epochs for training


# In[39]:


model.fit(x,y,xval,yval) # Train the model, the validation set is provided for evaluation of the model


# In[40]:


# Saving the model parameters
model.save('deeplens_params.npy')