Ejemplo n.º 1
0
    def start_evaluation(self, tol):
        dm = DataMatrix(self.lbl_img_list.text(), self.lbl_anno_dir.text(),
                        self.lbl_img_dir.text(), self.lbl_out_dir.text(),
                        self.lbl_ages_list.text(), tol)
        self.image_list = dm.image_list
        self.plainTextEdit.setPlainText(dm.get_dataset_properties())
        # insert data in table:
        tbl = dm.table_annodata

        self.tbl_anno_data.setRowCount(np.size(tbl, 0))
        self.tbl_anno_data.setColumnCount(np.size(tbl, 1))
        self.tbl_anno_data.setHorizontalHeaderLabels([
            'sc', 'matr', 'age', 'g', 'no.', 'a%', 'state', 'd0', 'd1', 'd0%',
            'd1%'
        ])
        try:
            self.tbl_anno_data.clearContents()
        except Exception as err:
            print(err)

        try:
            for row in range(np.size(tbl, 0)):
                for column in range(np.size(tbl, 1)):
                    try:
                        item = str(tbl[row][column].decode("utf-8"))
                        self.tbl_anno_data.setItem(row, column,
                                                   QTableWidgetItem(item))
                    except Exception as err:
                        pass  # print("unknown error" + str(err))
        except Exception as err:
            print("unknown error in table" + str(err))

        # plot histogram 1
        self.hist1_widget.canvas.figure.clear()
        ax = self.hist1_widget.canvas.figure.subplots()
        ax.clear()
        ax.hist(dm.hist1_canvas, bins=8)
        self.hist1_widget.canvas.draw()

        # plot histogram 2
        self.hist2_widget.canvas.figure.clear()
        ax = self.hist2_widget.canvas.figure.subplots()
        ax.clear()
        ax.hist(dm.hist2_canvas, bins=30)
        self.hist2_widget.canvas.draw()

        # plot histogram 2
        self.hist3_widget.canvas.figure.clear()
        ax = self.hist3_widget.canvas.figure.subplots()
        ax.clear()
        ax.hist(dm.num_value_0_with_large_sc, bins=100)
        self.hist3_widget.canvas.draw()

        # plot histogram 2
        self.hist4_widget.canvas.figure.clear()
        ax = self.hist4_widget.canvas.figure.subplots()
        ax.clear()
        ax.hist(dm.num_value_1_with_small_sc, bins=100)
        self.hist4_widget.canvas.draw()

        # plot miss attractive
        self.attr_widget.canvas.figure.clear()
        ax = self.attr_widget.canvas.figure.subplots()
        ax.clear()
        ax.axis('off')
        ax.set_title('Miss Aesthetics')
        ax.imshow(dm.attr_canvas)
        self.attr_widget.canvas.draw()

        # plot histogram ethnicity aesthetics
        self.ac_widget.canvas.figure.clear()
        ax = self.ac_widget.canvas.figure.subplots()
        ax.clear()
        x = dm.ethnic
        y = dm.score_list

        x, y = zip(*sorted(
            (xVal, np.mean([yVal for a, yVal in zip(x, y) if xVal == a]))
            for xVal in set(x)))
        ax.plot(x, y, '-', color='b')
        self.ac_widget.canvas.draw()

        # plot correlation of age and aesthetics
        self.age_data = dm.get_age_data()
        min, max, attr, avg, var, ethnic = self.age_data

        x = list(range(min, max))
        self.ac_widget2.canvas.figure.clear()
        ax = self.ac_widget2.canvas.figure.subplots()
        ax.clear()
        ax.set_title('Correlation of Aesthetics and Age')
        for i in range(0, max - min):
            for score in range(len(attr[i])):
                norm = colors.Normalize(0, 10)
                co = ethnic[i][score]
                ax.plot(min + i,
                        attr[i][score],
                        '.',
                        color=(.99 * co, .5 - 0.5 * co, .8 - .8 * co))

        ax.plot(x, avg, '-', color='b')

        self.ac_widget2.canvas.draw()
Ejemplo n.º 2
0
    def buttonClicked(self):
        sender = self.sender()

        if sender.text() == 'Image Textfile':
            # self.rot += 0.1
            print("< you pressed " + sender.text())
            fname = QFileDialog.getOpenFileName(
                self, 'Open file', 'c:\\',
                "Aesthetics data file (*.dat *.txt)")
            print(fname)
            self.lbl_img_list.setText(fname[0])

        elif sender.text() == 'Image directory':
            print("> you pressed " + sender.text())
            fname = QFileDialog.getExistingDirectory(self, 'Select Directory')
            print(fname)
            self.lbl_img_dir.setText(fname)

        elif sender.text() == 'Annotations directory':
            print("> you pressed " + sender.text())
            fname = QFileDialog.getExistingDirectory(self, 'Select Directory')
            print(fname)
            self.lbl_anno_dir.setText(fname)

        elif sender.text() == 'Output directory':
            print("> you pressed " + sender.text())
            fname = QFileDialog.getExistingDirectory(self, 'Select Directory')
            print(fname)
            self.lbl_out_dir.setText(fname)

        elif sender.text() == 'Start Evaluation':
            dm = DataMatrix(self.lbl_img_list.text(), self.lbl_anno_dir.text(),
                            self.lbl_img_dir.text(), self.lbl_out_dir.text(),
                            50)
            self.plainTextEdit.setPlainText(dm.get_dataset_properties())
            self.output_log.setPlainText(dm.output_log)
            # plot histogram 1
            self.hist1_widget.canvas.figure.clear()
            ax = self.hist1_widget.canvas.figure.subplots()
            ax.clear()
            ax.hist(dm.hist1_canvas)
            self.hist1_widget.canvas.draw()
            # plot histogram 2
            self.hist2_widget.canvas.figure.clear()
            ax = self.hist2_widget.canvas.figure.subplots()
            ax.clear()
            ax.hist(dm.hist2_canvas)
            self.hist2_widget.canvas.draw()
            # plot miss attractive
            self.attr_widget.canvas.figure.clear()
            ax = self.attr_widget.canvas.figure.subplots()
            ax.clear()
            ax.axis('off')
            ax.set_title('Miss Aesthetics')
            ax.imshow(dm.attr_canvas)
            self.attr_widget.canvas.draw()

            # plot miss attractive
            min, max, attr, avg, var = dm.get_age_data()
            x = list(range(min, max))
            self.ac_widget2.canvas.figure.clear()
            ax = self.ac_widget2.canvas.figure.subplots()
            ax.clear()
            ax.set_title('Correlation of Aesthetics and Age')
            for i in range(0, max - min):
                for score in attr[i]:
                    ax.plot(min + i, score, '.')
                    print(str(min + i) + ' ' + str(score))
            ax.plot(x, avg, '-', color='b')

            self.ac_widget2.canvas.draw()