def inference(self, sess, data, multi_crop=False): if multi_crop: raw_data = data (crops, flip_crops), idxs, sizes = net.multi_crop(data, size=0.75) data = np.concatenate( crops + flip_crops, axis=0 ) # print(raw_data.shape, data.shape) else: idxs = sizes = None pred, score, W, F = sess.run([self.pred_op, self.score_op, self.W, self.F], feed_dict={ self.inputs: data, self.is_training: False }) if multi_crop: # print(score.shape) num_n, num_classes = score.shape[0]/10, score.shape[1] shape = (10, num_n, num_classes) score = score.reshape(shape) score = np.mean(score, axis=0) pred = np.argmax(score, axis=1) return pred, score, W, F, idxs, sizes
def multi_crop_test(): from scipy import misc import matplotlib.pyplot as plt from net_utils import multi_crop import numpy as np img = misc.imread('../temp/images.png', mode='RGB') crops, mask, flip_res, flip_mask = multi_crop(np.expand_dims(img, axis=0), size=0.7) # [top_left, top_right, bottom_left, bottom_right, center] f, ((ax1, ax2), (ax3, ax4), (ax5, ax6), (ax7, ax8)) = plt.subplots(4, 2) ### ax1: raw image ax1.imshow(img[:, ::-1, :]) ax1.set_title('Raw') ## ax2: top_left ax2.imshow(crops[0][0]) ax2.set_title('Top Left') ## ax3: top_right ax3.imshow(crops[1][0]) ax3.set_title('Top Right') ## ax4: bottom_left ax4.imshow(crops[2][0]) ax4.set_title('Bottom Left') ## ax5: bottom_right ax5.imshow(crops[3][0]) ax5.set_title('Bottom Right') ## ax6: center ax6.imshow(crops[4][0]) ax6.set_title('Center') # ## ax7: mask # ax7.imshow(mask[0]*20, cmap=plt.cm.jet) # ax7.set_title('Mask') # ## ax8 # ax8.imshow(img) # ax8.set_title('Raw') plt.tight_layout() plt.show()