Skip to content

Commit

Permalink
Debug Completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Santara committed Jul 17, 2016
1 parent 7ec70f7 commit 4072573
Show file tree
Hide file tree
Showing 10 changed files with 1,006 additions and 141 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1 +1,3 @@
Data/*
*.ckpt*
.ipynb_checkpoints/*
460 changes: 460 additions & 0 deletions Decoder_Spatial.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion IndianPinesTF.ipynb
Expand Up @@ -44,7 +44,7 @@
"\n",
"# We have chopped the IndianPines image into 28x28 pixels patches. \n",
"# We will classify each patch\n",
"IMAGE_SIZE = 31\n",
"IMAGE_SIZE = 21\n",
"IMAGE_PIXELS = IMAGE_SIZE * IMAGE_SIZE *220"
]
},
Expand Down
Binary file modified IndianPinesTF.pyc
Binary file not shown.
90 changes: 46 additions & 44 deletions IndianPines_DataSet_Preparation_Without_Augmentation.ipynb
Expand Up @@ -23,6 +23,7 @@
"import spectral\n",
"import scipy.ndimage\n",
"from skimage.transform import rotate\n",
"import os\n",
"%matplotlib inline"
]
},
Expand All @@ -42,8 +43,9 @@
},
"outputs": [],
"source": [
"input_mat = scipy.io.loadmat('data/Indian_pines.mat')['indian_pines']\n",
"target_mat = scipy.io.loadmat('data/Indian_pines_gt.mat')['indian_pines_gt']"
"DATA_PATH = os.path.join(os.getcwd(),\"Data\")\n",
"input_mat = scipy.io.loadmat(os.path.join(DATA_PATH, 'Indian_pines.mat'))['indian_pines']\n",
"target_mat = scipy.io.loadmat(os.path.join(DATA_PATH, 'Indian_pines_gt.mat'))['indian_pines_gt']"
]
},
{
Expand All @@ -65,7 +67,7 @@
"HEIGHT = input_mat.shape[0]\n",
"WIDTH = input_mat.shape[1]\n",
"BAND = input_mat.shape[2]\n",
"PATCH_SIZE = 37\n",
"PATCH_SIZE = 21\n",
"TRAIN_PATCH,TRAIN_LABELS,TEST_PATCH,TEST_LABELS = [],[],[],[]\n",
"CLASSES = [] \n",
"COUNT = 200 #Number of patches of each class\n",
Expand Down Expand Up @@ -189,21 +191,21 @@
"output_type": "stream",
"text": [
"46\n",
"1298\n",
"110\n",
"42\n",
"210\n",
"1378\n",
"547\n",
"152\n",
"340\n",
"730\n",
"28\n",
"147\n",
"356\n",
"20\n",
"807\n",
"2081\n",
"260\n",
"843\n",
"2245\n",
"481\n",
"205\n",
"663\n",
"81\n",
"62\n"
"1095\n",
"142\n",
"93\n"
]
}
],
Expand Down Expand Up @@ -244,7 +246,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": {
"collapsed": false
},
Expand All @@ -254,21 +256,21 @@
"output_type": "stream",
"text": [
"35\n",
"974\n",
"83\n",
"32\n",
"158\n",
"1034\n",
"411\n",
"114\n",
"255\n",
"548\n",
"21\n",
"111\n",
"267\n",
"15\n",
"606\n",
"1561\n",
"195\n",
"633\n",
"1684\n",
"361\n",
"154\n",
"498\n",
"61\n",
"47\n"
"822\n",
"107\n",
"70\n"
]
}
],
Expand All @@ -287,7 +289,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"metadata": {
"collapsed": false
},
Expand All @@ -306,7 +308,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 12,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -341,7 +343,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 13,
"metadata": {
"collapsed": false
},
Expand All @@ -352,18 +354,18 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"TRAIN_PATCH = TRAIN_PATCH.reshape((-1,220,37,37))"
"TRAIN_PATCH = TRAIN_PATCH.reshape((-1,220,PATCH_SIZE,PATCH_SIZE))"
]
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 15,
"metadata": {
"collapsed": false
},
Expand All @@ -384,7 +386,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 16,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -424,7 +426,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 17,
"metadata": {
"collapsed": false
},
Expand All @@ -433,7 +435,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"1691\n",
"2170\n",
"3200\n"
]
}
Expand Down Expand Up @@ -461,7 +463,7 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 18,
"metadata": {
"collapsed": false
},
Expand All @@ -486,10 +488,10 @@
" train_dict = {}\n",
" start = i * (COUNT*2)\n",
" end = (i+1) * (COUNT*2)\n",
" file_name = 'Train_15_'+str(i+1)+'.mat'\n",
" file_name = 'Train_'+str(PATCH_SIZE)+'_'+str(i+1)+'.mat'\n",
" train_dict[\"train_patch\"] = TRAIN_PATCH[start:end]\n",
" train_dict[\"train_labels\"] = TRAIN_LABELS[start:end]\n",
" scipy.io.savemat(file_name,train_dict)\n",
" scipy.io.savemat(os.path.join(DATA_PATH, file_name),train_dict)\n",
" print i"
]
},
Expand All @@ -503,7 +505,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 19,
"metadata": {
"collapsed": true
},
Expand All @@ -513,26 +515,26 @@
" test_dict = {}\n",
" start = i * (COUNT*2)\n",
" end = (i+1) * (COUNT*2)\n",
" file_name = 'Test_15_'+str(i+1)+'.mat'\n",
" file_name = 'Test_'+str(PATCH_SIZE)+'_'+str(i+1)+'.mat'\n",
" test_dict[\"test_patch\"] = TEST_PATCH[start:end]\n",
" test_dict[\"test_labels\"] = TEST_LABELS[start:end]\n",
" scipy.io.savemat(file_name,test_dict)"
" scipy.io.savemat(os.path.join(DATA_PATH, file_name),test_dict)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4"
"8"
]
},
"execution_count": 15,
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
119 changes: 119 additions & 0 deletions Spatial_dataset.py
@@ -0,0 +1,119 @@

# coding: utf-8

# In[1]:

import tensorflow as tf
import numpy as np
import scipy.io as io


# In[2]:

""" Functions for handling the IndianPines data"""

class DataSet(object):

def __init__(self, images, labels, dtype=tf.float32):

"""Construct a DataSet.
FIXME: fake_data options
one_hot arg is used only if fake_data is true. `dtype` can be either
`uint8` to leave the input as `[0, 255]`, or `float32` to rescale into
`[0, 1]`.
"""
#COnvert the shape from [num_exmaple,channels, height, width]
#to [num_exmaple, height, width, channels]
images = np.transpose(images,(0,2,3,1))
#labels[:] = [i - 1 for i in labels]
labels = np.transpose(labels)


dtype = tf.as_dtype(dtype).base_dtype
if dtype not in (tf.uint8, tf.float32):
raise TypeError('Invalid image dtype %r, expected uint8 or float32' %
dtype)


assert images.shape[0] == labels.shape[0], (
'images.shape: %s labels.shape: %s' % (images.shape, labels.shape))
self._num_examples = images.shape[0]

# Convert shape from [num examples, rows, columns, depth]
# to [num examples, rows*columns*depth]
images = images.reshape(images.shape[0],images.shape[1] * images.shape[2] * images.shape[3])

# if dtype == tf.float32:
# # Convert from [0, 255] -> [0.0, 1.0].
# images = images.astype(numpy.float32)
# images = numpy.multiply(images, 1.0 / 255.0)

self._images = images
self._labels = labels
self._epochs_completed = 0
self._index_in_epoch = 0

@property
def images(self):
return self._images

@property
def labels(self):
return self._labels

@property
def num_examples(self):
return self._num_examples

@property
def epochs_completed(self):
return self._epochs_completed

def next_batch(self, batch_size):
"""Return the next `batch_size` examples from this data set."""
start = self._index_in_epoch
self._index_in_epoch += batch_size
if self._index_in_epoch > self._num_examples:
# Finished epoch
self._epochs_completed += 1
# Shuffle the data
perm = np.arange(self._num_examples)
np.random.shuffle(perm)
self._images = self._images[perm]
self._labels = self._labels[perm]
# Start next epoch
start = 0
self._index_in_epoch = batch_size
assert batch_size <= self._num_examples
end = self._index_in_epoch
return self._images[start:end], np.reshape(self._labels[start:end],len(self._labels[start:end]))



# In[20]:





def read_data_sets(directory,value, dtype=tf.float32):

images = io.loadmat(directory)[value+'_patch']
labels = io.loadmat(directory)[value+'_labels']

data_sets = DataSet(images, labels, dtype=dtype)

return data_sets


# In[ ]:




# In[ ]:



Binary file added Spatial_dataset.pyc
Binary file not shown.
5 changes: 5 additions & 0 deletions checkpoint
@@ -0,0 +1,5 @@
model_checkpoint_path: "model-spatial-21X21.ckpt-3999"
all_model_checkpoint_paths: "model-spatial-21X21.ckpt-999"
all_model_checkpoint_paths: "model-spatial-21X21.ckpt-1999"
all_model_checkpoint_paths: "model-spatial-21X21.ckpt-2999"
all_model_checkpoint_paths: "model-spatial-21X21.ckpt-3999"

0 comments on commit 4072573

Please sign in to comment.