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]:
Delete top layers:
In [42]:
# viewing last Conv block + top linear layers
[layer for layer in model.children()][-3:]
Out[42]:
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)
In [49]:
ls $VEGAS/summaryData
In [51]:
df = pd.read_csv(VEGAS + 'summaryData/' + 'AOI_2_Vegas_Roads_Sample.csv')
In [52]:
df.head()
Out[52]:
In [ ]:
data = ImageClassifierData.from_csv(vegas_csv_path, )
In [55]:
ls $VEGAS
In [66]:
ls $VEGAS/RGB-PanSharpen/
In [67]:
ls $VEGAS/MUL/
In [72]:
ls $VEGAS/PAN
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]:
In [79]:
os.listdir('SpaceNet_Roads_Sample')
Out[79]:
In [78]:
os.listdir('SpaceNet_Roads_Sample/AOI_2_Vegas_Roads_Sample')
Out[78]:
In [84]:
os.listdir(PARIS), os.listdir(PARIS + os.listdir(PARIS)[0])
Out[84]:
In [101]:
img = cv2.imread(f'{PARIS}/MUL/MUL_AOI_3_Paris_img432.tif')
# img *= 256
plt.imshow(img)
In [100]:
img.dtype
Out[100]:
In [107]:
img *= 100; img
Out[107]:
In [108]:
plt.imshow(img)
Out[108]:
In [135]:
img = cv2.imread(f'{PARIS}/MUL/MUL_AOI_3_Paris_img432.tif')
img[:,:,1] *= 100
plt.imshow(img)
Out[135]:
In [129]:
img.shape
Out[129]:
In [136]:
os.listdir(PARIS), os.listdir(PARIS + os.listdir(PARIS)[1])
Out[136]:
In [144]:
os.listdir(PARIS)[1]+'/'+os.listdir(PARIS + os.listdir(PARIS)[1])[0]
Out[144]:
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]:
In [167]:
img.max(), img.min()
Out[167]:
In [168]:
img = np.array([[255 * c / img.max() for c in r] for r in img])
In [ ]:
plt.imshow(img)
In [ ]:
In [97]:
img
Out[97]:
Are all of the sample images black or something?
In [88]:
PARIS
Out[88]:
In [89]:
os.getcwd()
Out[89]:
In [90]:
os.listdir(PARIS)
Out[90]:
In [ ]:
In [87]:
img
Out[87]:
In [ ]:
In [ ]:
In [59]:
img
Out[59]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: