Commit 87c93ef2 authored by josh's avatar josh
Browse files

test

parent f8e02017
%% Cell type:code id: tags:
``` python
import matplotlib.pyplot as plt
import numpy as np
from pathlib import Path
from PIL import Image
from sample.model import HDRModel
from trainModel import getSamples
```
%% Cell type:code id: tags:
``` python
def plt2Images(imgArr1, title1, imgArr2, title2):
f, axarr = plt.subplots(1, 2)
axarr[0].imshow(imgArr1, cmap="Greys_r")
axarr[0].set_title(title1)
axarr[1].imshow(imgArr2, cmap="Greys_r")
axarr[1].set_title(title2)
plt.show()
SAMPLE_FOLDER = "tempTrain"
TEST_FOLDER = "testTemp"
TEST_FOLDER = "testTemp"
```
%% Cell type:markdown id: tags:
# Pull in paired slices and masks
%% Cell type:code id: tags:
``` python
(xTrain, yTrain) = getSamples(Path(SAMPLE_FOLDER))
yTrain[0].shape
print(xTrain.shape)
print(yTrain.shape)
```
%% Output
mask size: (128, 128, 3)
mask size: (128, 128, 3)
mask size: (128, 128, 3)
mask size: (128, 128, 3)
mask size: (128, 128, 3)
mask size: (128, 128, 3)
mask size: (128, 128, 3)
mask size: (128, 128, 3)
mask size: (128, 128, 3)
mask size: (128, 128, 3)
(128, 128)
(10, 128, 128, 3)
(10, 128, 128)
%% Cell type:code id: tags:
``` python
f, axarr = plt.subplots(1, 2)
axarr[0].imshow(xTrain[0], cmap="Greys_r")
axarr[0].set_title("IMAGE")
axarr[1].imshow(yTrain[0], cmap="Greys_r")
axarr[1].set_title("MASK")
plt.show()
plt2Images(xTrain[0], "IMAGE", yTrain[0], "MASK")
```
%% Output
%% Cell type:code id: tags:
``` python
xDim = xTrain[0].shape[0]
yDim = xTrain[0].shape[1]
shape = (xDim, yDim, 3)
```
%% Cell type:markdown id: tags:
# Load Model: VGG16/Random Forest
%% Cell type:code id: tags:
``` python
model = HDRModel(shape=shape)
```
%% Cell type:markdown id: tags:
# Fit Model
%% Cell type:code id: tags:
``` python
model.fit(xTrain, yTrain)
```
%% Output
[Parallel(n_jobs=-1)]: Using backend ThreadingBackend with 4 concurrent workers.
[Parallel(n_jobs=-1)]: Done 42 tasks | elapsed: 1.2min
[Parallel(n_jobs=-1)]: Done 50 out of 50 | elapsed: 1.4min finished
[Parallel(n_jobs=-1)]: Done 42 tasks | elapsed: 1.1min
[Parallel(n_jobs=-1)]: Done 50 out of 50 | elapsed: 1.3min finished
%% Cell type:markdown id: tags:
# Load Test Images
%% Cell type:code id: tags:
``` python
testPaths = [pth for pth in Path(TEST_FOLDER).iterdir()]
print(len(testPaths))
```
%% Output
9
%% Cell type:code id: tags:
``` python
def show2Images(imgArr1, title1, imgArr2, title2):
f, axarr = plt.subplots(1, 2)
axarr[0].imshow(imgArr1, cmap="Greys_r")
axarr[0].set_title(title1)
axarr[1].imshow(imgArr2, cmap="Greys_r")
axarr[1].set_title(title2)
plt.show()
```
%% Cell type:code id: tags:
``` python
image = np.array(Image.open(testPaths[0]))
image = np.array(Image.open(testPaths[2]))
pred = model.predict(image)
show2Images(image, "INPUT", pred, "PREDICTION")
plt2Images(image, "INPUT", pred, "PREDICTION")
```
%% Output
[Parallel(n_jobs=4)]: Using backend ThreadingBackend with 4 concurrent workers.
[Parallel(n_jobs=4)]: Done 42 tasks | elapsed: 0.5s
[Parallel(n_jobs=4)]: Done 50 out of 50 | elapsed: 0.6s finished
%% Cell type:code id: tags:
[Parallel(n_jobs=4)]: Done 42 tasks | elapsed: 0.4s
[Parallel(n_jobs=4)]: Done 50 out of 50 | elapsed: 0.5s finished
``` python
image = np.array(Image.open(testPaths[9]))
pred = model.predict(image)
show2Images(image, "INPUT", pred, "PREDICTION")
```
%% Output
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-32-1f887e89bb44> in <module>()
----> 1 image = np.array(Image.open(testPaths[9]))
2 pred = model.predict(image)
3
4 show2Images(image, "INPUT", pred, "PREDICTION")
IndexError: list index out of range
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```