%run './../interface/hyperspectral_image.ipynb'
%run './../interface/tensorflow_defaults.ipynb'
%run './../interface/tensorflow_functions.ipynb'
XTrain = tf.constant(value=hyimage.splitPixels(stratified=True).XTrain, dtype=tf.float32, name='XTrain')
YTrain = tf.constant(value=hyimage.splitPixels(stratified=True).YTrain, dtype=tf.int32, name='YTrain')
X = tf.placeholder_with_default(input=XTrain, shape=None, name='X')
Y = tf.placeholder_with_default(input=YTrain, shape=None, name='Y')
W = tf.Variable(tf.truncated_normal([hyimage.bandAmount, 1], seed=RANDOM_STATE), name='W')
b = tf.Variable(tf.truncated_normal([1, 1], seed=RANDOM_STATE), name='b')
YhatContinuous = tf.add(tf.matmul(X, W), b)
Yhat = tf.to_int32(YhatContinuous)
loss = tf.reduce_sum(tf.pow(tf.to_float(Y) - YhatContinuous, 2))
gd = tf.train.GradientDescentOptimizer(learning_rate=0.000005, name='GradientDescentOptimizer')
train_step = gd.minimize(loss)
tf.initialize_all_variables().run()
train_step.run()
loss.eval()
tfMinimize(_steps=500, _train_step=train_step, _loss=loss)
loss.eval()
W.eval()[0:5]
YhatContinuous.eval()[0:5]
%run './../interface/model_evaluation_functions.ipynb'
tfAccuracy(YTensor=Y, YHatTensor=Yhat)
feedTest = {X: hyimage.splitPixels(stratified=True).XTest, Y: hyimage.splitPixels(stratified=True).YTest}
tfAccuracy(YTensor=Y, YHatTensor=Yhat, feed=feedTest)
compareLabels(originalLabels=hyimage.splitPixels(stratified=True).YTest, predictedLabels=Yhat.eval(feed_dict=feedTest))
feedAll = {X: hyimage.pixelsScaled, Y: hyimage.pixelLabels}
tfAccuracy(YTensor=Y, YHatTensor=Yhat, feed=feedAll)
hyImageCompare(hyimage, Yhat.eval(feed_dict=feedAll).reshape(hyimage.labels.shape))