Exemplo n.º 1
0
    parser.add_argument('-f', '--flip', dest='flip', action='store_true')
    parser.add_argument('-de',
                        '--denoise',
                        dest='denoise',
                        action='store_true')
    return parser.parse_args()


args = get_args()

u.set_gray(args.gray)
u.set_cs(args.cs)

# Load the data and add an axis to the end of y
# so that it is three-dimensional
X, y = u.ips()
y = np.expand_dims(y, axis=3)

if args.test:
    X, y = X[:100], y[:100]

if args.jcs and X.shape[-1] == 2:
    X = np.expand_dims(X[:, :, :, 1], axis=3)

if args.flip:
    X = np.append(X, [np.fliplr(x) for x in X], axis=0)
    y = np.append(y, [np.fliplr(y) for y in y], axis=0)

if len(X.shape) == 3:
    X = np.expand_dims(X, axis=3)
Exemplo n.º 2
0
from iou import iou_metric

import numpy as np

model = u.load_unet()

all_ids = u.img_ids(train=True)

batch_size = 64
i = 0

id_batch = all_ids[i * batch_size:(i + 1) * batch_size]
ious = dict()

while i * batch_size < len(all_ids) - 1:
    batch, y = u.ips(for_ids=id_batch)
    if len(batch.shape) == 3:
        batch = np.expand_dims(batch, axis=3)

    p = model.predict(batch, batch_size=batch_size)[:, :, :, 0]
    for img_id, true, pred in zip(id_batch, y, p):
        ious[img_id] = iou_metric(true, pred)

    i += 1
    id_batch = all_ids[i * batch_size:(i + 1) * batch_size]

ious = sorted(ious, key=lambda kv: kv[1])
with open('ious.csv', 'w') as f:
    for iou_pair in ious:
        print('%s:%f' % (iou_pair[0], iou_pair[1]))
        f.write('%s:%f\n' % (iou_pair[0], iou_pair[1]))
Exemplo n.º 3
0
                        action='store_true')
    parser.add_argument('-dp', '--depth', dest='depth', action='store_true')
    parser.add_argument('-pp', '--prepro', dest='prepro', action='store_true')
    return parser.parse_args()


args = get_args()

u.set_gray(args.gray)
u.set_cs(args.cs)
u.set_depth(args.depth)

# Load the data and add an axis to the end of y
# so that it is three-dimensional
if args.depth:
    X_w_depths, y = u.ips()
    X, depths = X_w_depths

    depths = depths.astype(np.float32)
    mu, sigma = np.mean(depths), np.std(depths)
    depths = (depths - mu) / sigma
else:
    X, y = u.ips()

y = np.expand_dims(y, axis=3)

if args.test:
    X, y = X[:100], y[:100]
    if args.depth: depths = depths[:100]

if args.jcs and X.shape[-1] == 2:
Exemplo n.º 4
0
model = model_from_json(json)
model.load_weights(join('models', name, 'model.h5'))

num_chan = model.layers[0].input_shape[-1]
if num_chan == 3:
    u.set_gray(False)
    u.set_cs(False)
elif num_chan == 2:
    u.set_cs(True)
else:
    u.set_cs(False)

ids = u.img_ids(train=True)
ids = np.random.choice(ids, args.num, replace=False)

X, y = u.ips(for_ids=ids)
if len(X.shape) == 3:
    X = np.expand_dims(X, axis=3)

u.unsilence()
print(X.shape, y.shape)

y_pred = model.predict(X)[:, :, :, 0]

if (X[0].shape)[2] == 2 or (X[0].shape)[2] == 1:
    X = X[:, :, :, 0]

for x, true, pred in zip(X, y, y_pred):
    if args.threshold >= 0.0:
        pred = (pred > args.threshold).astype(np.uint8)