示例#1
0
def plot_result(preds, labels, images):
    '''
  Display 5 images along with labels and predictions
          Args:
              preds (np array): array of predicted classes
              labels (np array): array of actual classes
              images (np array): array of images

  '''
    # set the title of the plot
    title = ""
    for ii in range(5):
        title = title + 3 * "-" + " {}({}) ".format(preds[ii],
                                                    labels[ii]) + 3 * "-"
    imshow_(torchvision.utils.make_grid(images[:5]), ax=(16, 6), title=title)
            if not os.path.isdir(dir_out):
                os.makedirs(dir_out)

            out = {"P":P_test, "Y":y_test, "S":AP_test}
            sio.savemat( dir_out+"/{}.mat".format(split), out)      

        # ---- Viz predictions -----
        if viz_predictions:
            max_classes = data.n_classes - 1
            # # Output all truth/prediction pairs
            plt.figure(split, figsize=(20,10))
            P_test_ = np.array(P_test)/float(n_classes-1)
            y_test_ = np.array(y_test)/float(n_classes-1)
            for i in range(len(y_test)):
                P_tmp = np.vstack([y_test_[i], P_test_[i]])
                plt.subplot(n_test,1,i+1); imshow_(P_tmp, vmin=0, vmax=1)
                plt.xticks([])
                plt.yticks([])
                acc = np.mean(y_test[i]==P_test[i])*100
                plt.ylabel("{:.01f}".format(acc))
                # plt.title("Acc: {:.03}%".format(100*np.mean(P_test[i]==y_test[i])))

        # ---- Viz weights -----
        if viz_weights and model_type is "TCN":
            # Output weights at the first layer
            plt.figure(2, figsize=(15,15))
            ws = model.get_weights()[0]
            for i in range(min(36, len(ws.T))):
                plt.subplot(6,6,i+1)
                # imshow_(model.get_weights()[0][i][:,:,0]+model.get_weights()[1][i])
                imshow_(np.squeeze(ws[:,:,:,i]).T)
示例#3
0
                os.makedirs(dir_out)

            out = {"P": P_test, "Y": y_test, "S": AP_test}
            sio.savemat(dir_out + "/{}.mat".format(split), out)

            # ---- Viz predictions -----
        if viz_predictions:
            max_classes = data.n_classes - 1
            # # Output all truth/prediction pairs
            plt.figure(split, figsize=(20, 10))
            P_test_ = np.array(P_test) / float(n_classes - 1)
            y_test_ = np.array(y_test) / float(n_classes - 1)
            for i in range(len(y_test)):
                P_tmp = np.vstack([y_test_[i], P_test_[i]])
                plt.subplot(n_test, 1, i + 1)
                imshow_(P_tmp, vmin=0, vmax=1)
                plt.xticks([])
                plt.yticks([])
                acc = np.mean(y_test[i] == P_test[i]) * 100
                plt.ylabel("{:.01f}".format(acc))
                # plt.title("Acc: {:.03}%".format(100*np.mean(P_test[i]==y_test[i])))

        # ---- Viz weights -----
        if viz_weights and model_type is "TCN":
            # Output weights at the first layer
            plt.figure(2, figsize=(15, 15))
            ws = model.get_weights()[0]
            for i in range(min(36, len(ws.T))):
                plt.subplot(6, 6, i + 1)
                # imshow_(model.get_weights()[0][i][:,:,0]+model.get_weights()[1][i])
                imshow_(np.squeeze(ws[:, :, :, i]).T)
示例#4
0
res = sio.loadmat(result_path)

P_test = res['P'][0]
y_test = res['Y'][0]

max_classes = data.n_classes - 1
n_classes = data.n_classes
n_test = len(X_test)

print('- dataset: {}'.format(dataset))
print('- max_classes: {}'.format(max_classes))

# # Output all truth/prediction pairs
plt.figure(split, figsize=(20, 10))
P_test_ = np.array(P_test) / float(n_classes - 1)
y_test_ = np.array(y_test) / float(n_classes - 1)

for i in range(len(y_test)):
    P_tmp = np.vstack([y_test_[i], P_test_[i]])

    print(P_tmp.shape)

    plt.subplot(n_test, 1, i + 1)
    imshow_(P_tmp, vmin=0.0, vmax=1.0)
    plt.xticks([])
    plt.yticks([])
    acc = np.mean(y_test[i] == P_test[i]) * 100
    plt.ylabel("{:.01f}".format(acc))
    # plt.title("Acc: {:.03}%".format(100*np.mean(P_test[i]==y_test[i]))

plt.show()