Пример #1
0
 def draw_iqa(img, q, target_a, pred_a):
     fig, ax = tfplot.subplots(figsize=(6, 6))
     ax.imshow(img)
     ax.set_title(question2str(q))
     ax.set_xlabel(
         answer2str(target_a) + answer2str(pred_a, 'Predicted'))
     return fig
Пример #2
0
    def update3(self):
        q_idx = self.comboBox.currentIndex()
        c_idx = self.comboBox_2.currentIndex()

        # find all qv, a, for selected object in this image
        qv_list = []
        a_list = []
        img = None

        for i in range(NUM_Q * NUM_SHAPE):
            img, q, a = self.getitem(self.currentImgIdx + i)
            qv_list.append(q)
            a_list.append(a)
            img = img
        qv = np.array(qv_list)
        a = np.array(a_list)
        idx = np.where(qv[:, c_idx] == 1)[0]
        if len(idx) <= 0:
            error = QtWidgets.QErrorMessage(self.widget)
            error.showMessage("Selected Object is not in the image!")
            return
        this_qv = qv[idx]
        this_a = a[idx]

        # select question and answer for this objects
        cur_qv = this_qv[q_idx]
        cur_a = this_a[q_idx]

        img = img / 255.

        # query for answer
        pa, ta = self.RN.predict(img, cur_qv, cur_a)
        predicted_answer = answer2str(pa)
        true_answer = answer2str(ta)
        QtWidgets.QMessageBox.information(
            self.widget, "Prediction Result",
            "Predicted Answer: %s | True Answer: %s" %
            (predicted_answer, true_answer))
Пример #3
0
        def draw_iqa(img, q, target_a, pred_a, weights):
            d = self.d
            H, W = img.shape[:2]

            weights = weights.reshape(d*d, d*d)
            weights_a2b = np.mean(weights, axis=1).reshape(4,4)
            weights_b2a = np.mean(np.transpose(weights), axis=1).reshape(4,4)
            mean_w = (weights_a2b + weights_b2a) / 2
            mean_w = mean_w / np.max(mean_w)



            # print(mean_w.shape, img.shape)
            # print("===========")

            fig, ax = tfplot.subplots(figsize=(6, 6))
            ax.imshow(img, extent=[0,H,0,W])
            mid = ax.imshow(mean_w, cmap='jet',
                      alpha=0.5, extent=[0, H, 0, W])
            fig.colorbar(mid)
            ax.set_title(question2str(q))
            ax.set_xlabel(answer2str(target_a)+answer2str(pred_a, 'Predicted'))
            return fig