Exemplo n.º 1
0
model = Conv2D(64, (3, 3), padding='same', name='conv15')(model)
model = Activation('relu', name='act15')(model)

model = Conv2D(64, (3, 3), padding='same', name='conv16')(model)
model = Activation('relu', name='act16')(model)
model = Conv2D(64, (3, 3), padding='same', name='conv17')(model)
model = Activation('relu', name='act17')(model)
model = Conv2D(64, (3, 3), padding='same', name='conv18')(model)
model = Activation('relu', name='act18')(model)
model = Conv2D(64, (3, 3), padding='same', name='conv19')(model)
model = Activation('relu', name='act19')(model)
model = Conv2D(1, (3, 3), padding='same', name='conv20')(model)
model = Activation('relu', name='act20')(model)
res_img = model

output_img = merge([res_img, input_img])

model = Model(input_img, output_img)

model.load_weights('vdsr_model_edges.h5')

img = image.load_img('./patch.png', grayscale=True, target_size=(41, 41, 1))
x = image.img_to_array(img)
x = x.astype('float32') / 255
x = np.expand_dims(x, axis=0)

pred = model.predict(x)

test_img = np.reshape(pred, (41, 41))

imsave('test_img.png', test_img)
        X_train = hyper_net.transform(X_train)
        X_test = hyper_net.transform(X_test)

        inp = Input((X_train.shape[1],))
        fc = Dense(n_class)(inp)
        model = Activation('softmax')(fc)
        model = Model(inp, model)

        model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='Adadelta')
        callbacks = [cm.custom_stopping(value=cm.loss, verbose=2)]

        model.fit(X_train, y[train_idx], batch_size=len(X_train),
                  epochs=4*cm.n_ep,#The drawback of the method is that it requires more iterations to converge (loss <= cm.loss)
                   verbose=0, callbacks=callbacks, validation_data=(X_train, y[train_idx]))

        y_pred = model.predict(X_test)
        y_pred = np.argmax(y_pred, axis=1)

        y_true = np.argmax(y[test_idx], axis=1)

        acc_fold = accuracy_score(y_true, y_pred)
        avg_acc.append(acc_fold)

        recall_fold = recall_score(y_true, y_pred, average='macro')
        avg_recall.append(recall_fold)

        f1_fold = f1_score(y_true, y_pred, average='macro')
        avg_f1.append(f1_fold)

        print('Accuracy[{:.4f}] Recall[{:.4f}] F1[{:.4f}] at fold[{}]'.format(acc_fold, recall_fold, f1_fold, i))
        print('______________________________________________________')
Exemplo n.º 3
0
model = Activation('relu', name='act17')(model)
model = Conv2D(64, (3, 3), padding='same', name='conv18')(model)
model = Activation('relu', name='act18')(model)
model = Conv2D(64, (3, 3), padding='same', name='conv19')(model)
model = Activation('relu', name='act19')(model)
model = Conv2D(1, (3, 3), padding='same', name='conv20')(model)
# model = Activation('relu', name='act20')(model)
res_img = model

output_img = add([res_img, input_img])

model = Model(input_img, output_img)

model.load_weights('checkpoints2/vdsr-200-32.21.hdf5')

pred = model.predict(data_input, batch_size=1)
sess = tf.InteractiveSession()
print(sess.run(PSNR(data_label, pred)))
print(data_label.shape)
print(data_input.shape)
print(tf.shape(pred))
y = np.reshape(data_label, [256, 256])
t = np.reshape(data_input, [256, 256])
c = np.reshape(pred, [256, 256])

# sio.savemat("yuantu.mat", {'yuan': y})
# sio.savemat("chongjian.mat", {'jian': c})

ax1 = plt.subplot(1, 3, 1)
plt.imshow(y, cmap='gray')
ax2 = plt.subplot(1, 3, 2)