Created
March 2, 2017 17:35
-
-
Save meetps/4a5e61aa0dd4580f76e95ea0afff497d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# def predict_id(id, model, trs): | |
# img = utils.M(id) | |
# x = utils.stretch_n(img) | |
# cnv = np.zeros((960, 960, 8)).astype(np.float32) | |
# prd = np.zeros((n_classes, 960, 960)).astype(np.float32) | |
# cnv[:img.shape[0], :img.shape[1], :] = x | |
# for i in range(0, 6): | |
# line = [] | |
# for j in range(0, 6): | |
# line.append(cnv[i * ISZ:(i + 1) * ISZ, j * ISZ:(j + 1) * ISZ]) | |
# x = 2 * np.transpose(line, (0, 3, 1, 2)) - 1 | |
# x = np.transpose(x, (0,2,3,1)) | |
# tmp = model.predict(x, batch_size=4) | |
# for j in range(tmp.shape[0]): | |
# prd[:, i * ISZ:(i + 1) * ISZ, j * ISZ:(j + 1) * ISZ] = tmp[j] | |
# # trs = [0.4, 0.1, 0.4, 0.3, 0.3, 0.5, 0.3, 0.6, 0.1, 0.1] | |
# for i in range(n_classes): | |
# prd[i] = prd[i] > trs[i] | |
# return prd[:, :img.shape[0], :img.shape[1]] | |
# def check_predict(id='6120_2_3'): | |
# params = {'input_shape':(n_channels, img_rows, img_cols), | |
# 'n_classes':n_classes, | |
# 'feat_scale':feat_scale} | |
# model = unet(params) | |
# model.load_weights('./savedModel/myModel.hdf5') | |
# model.compile(optimizer=Adam(), | |
# loss='binary_crossentropy', | |
# metrics=[jaccard_coef, jaccard_coef_int, 'accuracy']) | |
# msk = predict_id(id, model, [0.4, 0.1, 0.4, 0.3, 0.3, 0.5, 0.3, 0.6, 0.1, 0.1]) | |
# img = M(id) | |
# plt.figure() | |
# ax1 = plt.subplot(121) | |
# ax1.set_title('image ID:6120_2_3') | |
# ax1.imshow(img[:, :, 5], cmap=plt.get_cmap('gist_ncar')) | |
# ax2 = plt.subplot(122) | |
# ax2.set_title('predict bldg pixels') | |
# ax2.imshow(msk[0], cmap=plt.get_cmap('gray')) | |
# plt.show() | |
# ax3 = plt.subplot(133) | |
# ax3.set_title('predict bldg polygones') | |
# ax3.imshow(mask_for_polygons(mask_to_polygons(msk[0], epsilon=1), img.shape[:2]), cmap=plt.get_cmap('gray')) | |
############ test | |
# params = {'input_shape':(n_channels, img_rows, img_cols), | |
# 'n_classes':n_classes, | |
# 'feat_scale':feat_scale} | |
# model = unet(params) | |
# model.load_weights('./savedModel/myModel.hdf5') | |
# model.compile(optimizer=Adam(), | |
# loss='binary_crossentropy', | |
# metrics=[jaccard_coef, jaccard_coef_int, 'accuracy']) | |
# id='6120_2_3' | |
# trs = [0.4, 0.1, 0.4, 0.3, 0.3, 0.5, 0.3, 0.6, 0.1, 0.1] | |
# img = np.load('results/img.npy') | |
# x = np.load('results/x.npy') | |
# cnv = np.zeros((960, 960, 8)).astype(np.float32) | |
# prd = np.zeros((n_classes, 960, 960)).astype(np.float32) | |
# cnv[:img.shape[0], :img.shape[1], :] = x | |
# for i in range(0, 6): | |
# line = [] | |
# for j in range(0, 6): | |
# line.append(cnv[i * ISZ:(i + 1) * ISZ, j * ISZ:(j + 1) * ISZ]) | |
# x = 2 * np.transpose(line, (0, 3, 1, 2)) - 1 | |
# x = np.transpose(x, (0,2,3,1)) | |
# tmp = model.predict(x, batch_size=4) | |
# for j in range(tmp.shape[0]): | |
# prd[:, i * ISZ:(i + 1) * ISZ, j * ISZ:(j + 1) * ISZ] = tmp[j] | |
# # trs = [0.4, 0.1, 0.4, 0.3, 0.3, 0.5, 0.3, 0.6, 0.1, 0.1] | |
# for i in range(n_classes): | |
# prd[i] = prd[i] > trs[i] | |
# msk = prd[:, :img.shape[0], :img.shape[1]] | |
# # img = M(id) | |
# plt.figure() | |
# ax1 = plt.subplot(121) | |
# ax1.set_title('image ID:6120_2_3') | |
# ax1.imshow(img[:, :, 5], cmap=plt.get_cmap('gist_ncar')) | |
# ax2 = plt.subplot(122) | |
# ax2.set_title('predict bldg pixels') | |
# ax2.imshow(msk[0], cmap=plt.get_cmap('gray')) | |
# plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment