In [1]:
%matplotlib inline
%reload_ext autoreload
%autoreload 2

from fastai.imports import *

# from fastai.transforms import import *
from fastai.conv_learner import *
from fastai.model import *
from fastai.dataset import *
from fastai.sgdr import *

In [2]:
PATH = 'SpaceNet_Roads_Sample/'

In [3]:
dirs = os.listdir(PATH)
dirs.sort()

In [4]:
VEGAS, PARIS, SHANG, KHART = [PATH + directory + '/' for directory in dirs]

In [5]:
model = resnet34(True)

In [26]:
model


Out[26]:
ResNet (
  (conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
  (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True)
  (relu): ReLU (inplace)
  (maxpool): MaxPool2d (size=(3, 3), stride=(2, 2), padding=(1, 1), dilation=(1, 1))
  (layer1): Sequential (
    (0): BasicBlock (
      (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True)
    )
    (1): BasicBlock (
      (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True)
    )
    (2): BasicBlock (
      (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True)
    )
  )
  (layer2): Sequential (
    (0): BasicBlock (
      (conv1): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True)
      (downsample): Sequential (
        (0): Conv2d(64, 128, kernel_size=(1, 1), stride=(2, 2), bias=False)
        (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True)
      )
    )
    (1): BasicBlock (
      (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True)
    )
    (2): BasicBlock (
      (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True)
    )
    (3): BasicBlock (
      (conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True)
    )
  )
  (layer3): Sequential (
    (0): BasicBlock (
      (conv1): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
      (downsample): Sequential (
        (0): Conv2d(128, 256, kernel_size=(1, 1), stride=(2, 2), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
      )
    )
    (1): BasicBlock (
      (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
    )
    (2): BasicBlock (
      (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
    )
    (3): BasicBlock (
      (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
    )
    (4): BasicBlock (
      (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
    )
    (5): BasicBlock (
      (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True)
    )
  )
  (layer4): Sequential (
    (0): BasicBlock (
      (conv1): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
      (downsample): Sequential (
        (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)
        (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
      )
    )
    (1): BasicBlock (
      (conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
    )
    (2): BasicBlock (
      (conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
      (relu): ReLU (inplace)
      (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
      (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
    )
  )
  (avgpool): AvgPool2d (size=7, stride=7, padding=0, ceil_mode=False, count_include_pad=True)
  (fc): Linear (512 -> 1000)
)

Delete top layers:


In [42]:
# viewing last Conv block + top linear layers
[layer for layer in model.children()][-3:]


Out[42]:
[Sequential (
   (0): BasicBlock (
     (conv1): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
     (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
     (relu): ReLU (inplace)
     (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
     (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
     (downsample): Sequential (
       (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)
       (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
     )
   )
   (1): BasicBlock (
     (conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
     (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
     (relu): ReLU (inplace)
     (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
     (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
   )
   (2): BasicBlock (
     (conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
     (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
     (relu): ReLU (inplace)
     (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
     (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True)
   )
 ),
 AvgPool2d (size=7, stride=7, padding=0, ceil_mode=False, count_include_pad=True),
 Linear (512 -> 1000)]

In [6]:
model = nn.Sequential(*children(model)[:-2],
                      nn.Conv2d(512, 1, 3, padding=1), # 1 output bc looking for 1 class
                      nn.AdaptiveAvgPool2d(1), Flatten(), # 2 layers here (pool & flatn)
                      nn.LogSoftmax())

Data


In [11]:
vegas_csv_path = VEGAS + 'summaryData/' + 'AOI_2_Vegas_Roads_Sample.csv'
vegas_train_folder = VEGAS + 'RGB-PanSharpen'

In [12]:
sz = 224
bs = 64
tfms = tfms_from_model(model, sz, aug_tfms=transforms_top_down, max_zoom=1.1)
data = ImageClassifierData.from_csv(PATH, vegas_train_folder, vegas_csv_path, tfms=tfms,
                                    val_idxs = [0])
# ImageClassifierData.from_paths(PATH, val_name='test', tfms=tfms, bs=bs)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-ddc9e6f7611a> in <module>()
      3 tfms = tfms_from_model(model, sz, aug_tfms=transforms_top_down, max_zoom=1.1)
      4 data = ImageClassifierData.from_csv(PATH, vegas_train_folder, vegas_csv_path, tfms=tfms,
----> 5                                     val_idxs = [0])
      6 # ImageClassifierData.from_paths(PATH, val_name='test', tfms=tfms, bs=bs)

~/spacenet/fastai/dataset.py in from_csv(self, path, folder, csv_fname, bs, tfms, val_idxs, suffix, test_name, continuous, skip_header, num_workers)
    300     def from_csv(self, path, folder, csv_fname, bs=64, tfms=(None,None),
    301                val_idxs=None, suffix='', test_name=None, continuous=False, skip_header=True, num_workers=8):
--> 302         fnames,y,classes = csv_source(folder, csv_fname, skip_header, suffix, continuous=continuous)
    303         ((val_fnames,trn_fnames),(val_y,trn_y)) = split_by_idx(val_idxs, np.array(fnames), y)
    304 

~/spacenet/fastai/dataset.py in csv_source(folder, csv_file, skip_header, suffix, continuous)
     77 
     78 def csv_source(folder, csv_file, skip_header=True, suffix='', continuous=False):
---> 79     fnames,csv_labels,all_labels,label2idx = parse_csv_labels(csv_file, skip_header)
     80     full_names = [os.path.join(folder,fn+suffix) for fn in fnames]
     81     if continuous:

~/spacenet/fastai/dataset.py in parse_csv_labels(fn, skip_header)
     66     skip = 1 if skip_header else 0
     67     csv_lines = [o.strip().split(',') for o in open(fn)][skip:]
---> 68     csv_labels = {a:b.split(' ') for a,b in csv_lines}
     69     all_labels = sorted(list(set(p for o in csv_labels.values() for p in o)))
     70     label2idx = {v:k for k,v in enumerate(all_labels)}

~/spacenet/fastai/dataset.py in <dictcomp>(.0)
     66     skip = 1 if skip_header else 0
     67     csv_lines = [o.strip().split(',') for o in open(fn)][skip:]
---> 68     csv_labels = {a:b.split(' ') for a,b in csv_lines}
     69     all_labels = sorted(list(set(p for o in csv_labels.values() for p in o)))
     70     label2idx = {v:k for k,v in enumerate(all_labels)}

ValueError: too many values to unpack (expected 2)

In [49]:
ls $VEGAS/summaryData


AOI_2_Vegas_Roads_Sample.csv

In [51]:
df = pd.read_csv(VEGAS + 'summaryData/' + 'AOI_2_Vegas_Roads_Sample.csv')

In [52]:
df.head()


Out[52]:
ImageId WKT_Pix
0 AOI_2_Vegas_img408 LINESTRING (103.17 0.00, 106.45 54.10, 114.10 ...
1 AOI_2_Vegas_img408 LINESTRING (121.11 1300.00, 118.55 1001.51, 11...
2 AOI_2_Vegas_img408 LINESTRING (16.98 51.97, 106.45 54.10)
3 AOI_2_Vegas_img408 LINESTRING (118.55 1001.51, 224.85 1000.57, 41...
4 AOI_2_Vegas_img408 LINESTRING (143.65 284.74, 191.51 277.93, 440....

In [ ]:
data = ImageClassifierData.from_csv(vegas_csv_path, )

In [55]:
ls $VEGAS


geojson/  MUL/  MUL-PanSharpen/  PAN/  RGB-PanSharpen/  summaryData/

In [66]:
ls $VEGAS/RGB-PanSharpen/


RGB-PanSharpen_AOI_2_Vegas_img1454.tif*  RGB-PanSharpen_AOI_2_Vegas_img517.tif*
RGB-PanSharpen_AOI_2_Vegas_img1521.tif*  RGB-PanSharpen_AOI_2_Vegas_img699.tif*
RGB-PanSharpen_AOI_2_Vegas_img1539.tif*  RGB-PanSharpen_AOI_2_Vegas_img734.tif*
RGB-PanSharpen_AOI_2_Vegas_img230.tif*   RGB-PanSharpen_AOI_2_Vegas_img767.tif*
RGB-PanSharpen_AOI_2_Vegas_img408.tif*   RGB-PanSharpen_AOI_2_Vegas_img794.tif*

In [67]:
ls $VEGAS/MUL/


MUL_AOI_2_Vegas_img1454.tif*  MUL_AOI_2_Vegas_img517.tif*
MUL_AOI_2_Vegas_img1521.tif*  MUL_AOI_2_Vegas_img699.tif*
MUL_AOI_2_Vegas_img1539.tif*  MUL_AOI_2_Vegas_img734.tif*
MUL_AOI_2_Vegas_img230.tif*   MUL_AOI_2_Vegas_img767.tif*
MUL_AOI_2_Vegas_img408.tif*   MUL_AOI_2_Vegas_img794.tif*

In [72]:
ls $VEGAS/PAN


PAN_AOI_2_Vegas_img1454.tif*  PAN_AOI_2_Vegas_img517.tif*
PAN_AOI_2_Vegas_img1521.tif*  PAN_AOI_2_Vegas_img699.tif*
PAN_AOI_2_Vegas_img1539.tif*  PAN_AOI_2_Vegas_img734.tif*
PAN_AOI_2_Vegas_img230.tif*   PAN_AOI_2_Vegas_img767.tif*
PAN_AOI_2_Vegas_img408.tif*   PAN_AOI_2_Vegas_img794.tif*

In [73]:
# img = cv2.imread(f'{VEGAS}RGB-PanSharpen/RGB-PanSharpen_AOI_2_Vegas_img1521.tif')
# img = cv2.imread(f'{VEGAS}MUL/MUL_AOI_2_Vegas_img794.tif')
img = cv2.imread(f'{VEGAS}PAN/PAN_AOI_2_Vegas_img1454.tif')
plt.imshow(img)


Out[73]:
<matplotlib.image.AxesImage at 0x7feb8a3b7ba8>

In [79]:
os.listdir('SpaceNet_Roads_Sample')


Out[79]:
['AOI_5_Khartoum_Roads_Sample',
 'AOI_2_Vegas_Roads_Sample',
 'AOI_4_Shanghai_Roads_Sample',
 'AOI_3_Paris_Roads_Sample']

In [78]:
os.listdir('SpaceNet_Roads_Sample/AOI_2_Vegas_Roads_Sample')


Out[78]:
['MUL', 'RGB-PanSharpen', 'geojson', 'PAN', 'summaryData', 'MUL-PanSharpen']

In [84]:
os.listdir(PARIS), os.listdir(PARIS + os.listdir(PARIS)[0])


Out[84]:
(['MUL', 'RGB-PanSharpen', 'geojson', 'PAN', 'summaryData', 'MUL-PanSharpen'],
 ['MUL_AOI_3_Paris_img432.tif',
  'MUL_AOI_3_Paris_img38.tif',
  'MUL_AOI_3_Paris_img406.tif',
  'MUL_AOI_3_Paris_img340.tif',
  'MUL_AOI_3_Paris_img235.tif',
  'MUL_AOI_3_Paris_img307.tif',
  'MUL_AOI_3_Paris_img489.tif',
  'MUL_AOI_3_Paris_img28.tif',
  'MUL_AOI_3_Paris_img496.tif',
  'MUL_AOI_3_Paris_img84.tif'])

In [101]:
img = cv2.imread(f'{PARIS}/MUL/MUL_AOI_3_Paris_img432.tif')
# img *= 256
plt.imshow(img)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-101-61e4197acb19> in <module>()
----> 1 img = cv2.imread(f'{PARIS}/MUL/MUL_AOI_3_Paris_img432.tif',dtype=np.int16)
      2 # img *= 256
      3 plt.imshow(img)

TypeError: 'dtype' is an invalid keyword argument for this function

In [100]:
img.dtype


Out[100]:
dtype('uint8')

In [107]:
img *= 100; img


Out[107]:
array([[[100, 100, 100],
        [100, 100, 100],
        [100, 100, 100],
        ...,
        [200, 100, 100],
        [200, 100, 100],
        [200, 200, 100]],

       [[100, 100, 100],
        [100, 100, 100],
        [100, 100, 100],
        ...,
        [100, 100, 100],
        [100, 100, 100],
        [200, 100, 100]],

       [[100, 100, 100],
        [100, 100, 100],
        [100, 100, 100],
        ...,
        [100, 100, 100],
        [100, 100, 100],
        [100, 100, 100]],

       ...,

       [[200, 100, 100],
        [200, 100, 100],
        [100, 100, 100],
        ...,
        [100, 100, 100],
        [100, 100, 100],
        [100, 100, 100]],

       [[200, 100, 100],
        [200, 100, 100],
        [200, 100, 100],
        ...,
        [100, 100, 100],
        [100, 100, 100],
        [100, 100, 100]],

       [[100, 100, 100],
        [200, 100, 100],
        [200, 100, 100],
        ...,
        [100, 100, 100],
        [100, 100, 100],
        [100, 100, 100]]], dtype=uint8)

In [108]:
plt.imshow(img)


Out[108]:
<matplotlib.image.AxesImage at 0x7feb89e528d0>

In [135]:
img = cv2.imread(f'{PARIS}/MUL/MUL_AOI_3_Paris_img432.tif')
img[:,:,1] *= 100
plt.imshow(img)


Out[135]:
<matplotlib.image.AxesImage at 0x7feb837e4518>

In [129]:
img.shape


Out[129]:
(325, 325, 3)

In [136]:
os.listdir(PARIS), os.listdir(PARIS + os.listdir(PARIS)[1])


Out[136]:
(['MUL', 'RGB-PanSharpen', 'geojson', 'PAN', 'summaryData', 'MUL-PanSharpen'],
 ['RGB-PanSharpen_AOI_3_Paris_img84.tif',
  'RGB-PanSharpen_AOI_3_Paris_img235.tif',
  'RGB-PanSharpen_AOI_3_Paris_img340.tif',
  'RGB-PanSharpen_AOI_3_Paris_img406.tif',
  'RGB-PanSharpen_AOI_3_Paris_img432.tif',
  'RGB-PanSharpen_AOI_3_Paris_img496.tif',
  'RGB-PanSharpen_AOI_3_Paris_img38.tif',
  'RGB-PanSharpen_AOI_3_Paris_img307.tif',
  'RGB-PanSharpen_AOI_3_Paris_img489.tif',
  'RGB-PanSharpen_AOI_3_Paris_img28.tif'])

In [144]:
os.listdir(PARIS)[1]+'/'+os.listdir(PARIS + os.listdir(PARIS)[1])[0]


Out[144]:
'RGB-PanSharpen/RGB-PanSharpen_AOI_3_Paris_img84.tif'

In [165]:
# img = cv2.imread(f'{PARIS}/RGB-PanSharpen/RGB-PanSharpen_AOI_3_Paris_img84.tif')
img = cv2.imread(f'{PARIS}/RGB-PanSharpen/RGB-PanSharpen_AOI_3_Paris_img406.tif')
# img *= 80

# for i,e in enumerate(img):
#     img[i] = 255 * e / img.max()

plt.imshow(img)


Out[165]:
<matplotlib.image.AxesImage at 0x7feb8322e908>

In [167]:
img.max(), img.min()


Out[167]:
(7, 0)

In [168]:
img = np.array([[255 * c / img.max() for c in r] for r in img])


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-168-26fa5c262361> in <module>()
----> 1 img = np.array([[255 * c / img.max() for c in r] for r in img])

<ipython-input-168-26fa5c262361> in <listcomp>(.0)
----> 1 img = np.array([[255 * c / img.max() for c in r] for r in img])

<ipython-input-168-26fa5c262361> in <listcomp>(.0)
----> 1 img = np.array([[255 * c / img.max() for c in r] for r in img])

~/src/anaconda3/envs/fastai/lib/python3.6/site-packages/numpy/core/_methods.py in _amax(a, axis, out, keepdims)
     24 # small reductions
     25 def _amax(a, axis=None, out=None, keepdims=False):
---> 26     return umr_maximum(a, axis, None, out, keepdims)
     27 
     28 def _amin(a, axis=None, out=None, keepdims=False):

KeyboardInterrupt: 

In [ ]:
plt.imshow(img)

In [ ]:


In [97]:
img


Out[97]:
array([[[1, 1, 1],
        [1, 1, 1],
        [1, 1, 1],
        ...,
        [2, 1, 1],
        [2, 1, 1],
        [2, 2, 1]],

       [[1, 1, 1],
        [1, 1, 1],
        [1, 1, 1],
        ...,
        [1, 1, 1],
        [1, 1, 1],
        [2, 1, 1]],

       [[1, 1, 1],
        [1, 1, 1],
        [1, 1, 1],
        ...,
        [1, 1, 1],
        [1, 1, 1],
        [1, 1, 1]],

       ...,

       [[2, 1, 1],
        [2, 1, 1],
        [1, 1, 1],
        ...,
        [1, 1, 1],
        [1, 1, 1],
        [1, 1, 1]],

       [[2, 1, 1],
        [2, 1, 1],
        [2, 1, 1],
        ...,
        [1, 1, 1],
        [1, 1, 1],
        [1, 1, 1]],

       [[1, 1, 1],
        [2, 1, 1],
        [2, 1, 1],
        ...,
        [1, 1, 1],
        [1, 1, 1],
        [1, 1, 1]]], dtype=uint8)

Are all of the sample images black or something?


In [88]:
PARIS


Out[88]:
'SpaceNet_Roads_Sample/AOI_3_Paris_Roads_Sample/'

In [89]:
os.getcwd()


Out[89]:
'/home/ubuntu/spacenet'

In [90]:
os.listdir(PARIS)


Out[90]:
['MUL', 'RGB-PanSharpen', 'geojson', 'PAN', 'summaryData', 'MUL-PanSharpen']

In [ ]:


In [87]:
img


Out[87]:
array([[[1, 1, 1],
        [1, 1, 1],
        [1, 1, 1],
        ...,
        [2, 1, 1],
        [2, 1, 1],
        [2, 2, 1]],

       [[1, 1, 1],
        [1, 1, 1],
        [1, 1, 1],
        ...,
        [1, 1, 1],
        [1, 1, 1],
        [2, 1, 1]],

       [[1, 1, 1],
        [1, 1, 1],
        [1, 1, 1],
        ...,
        [1, 1, 1],
        [1, 1, 1],
        [1, 1, 1]],

       ...,

       [[2, 1, 1],
        [2, 1, 1],
        [1, 1, 1],
        ...,
        [1, 1, 1],
        [1, 1, 1],
        [1, 1, 1]],

       [[2, 1, 1],
        [2, 1, 1],
        [2, 1, 1],
        ...,
        [1, 1, 1],
        [1, 1, 1],
        [1, 1, 1]],

       [[1, 1, 1],
        [2, 1, 1],
        [2, 1, 1],
        ...,
        [1, 1, 1],
        [1, 1, 1],
        [1, 1, 1]]], dtype=uint8)

In [ ]:


In [ ]:


In [59]:
img


Out[59]:
array([[[1, 2, 1],
        [1, 2, 1],
        [1, 2, 1],
        ...,
        [1, 2, 1],
        [1, 2, 1],
        [1, 2, 1]],

       [[1, 2, 1],
        [1, 2, 1],
        [1, 2, 1],
        ...,
        [1, 2, 1],
        [1, 2, 1],
        [1, 2, 1]],

       [[1, 2, 1],
        [1, 2, 1],
        [1, 2, 1],
        ...,
        [1, 2, 1],
        [1, 2, 1],
        [1, 2, 1]],

       ...,

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]]], dtype=uint8)

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: