示例#1
0
文件: 1.py 项目: Don98/Loss
def draw_each_class_ap(epochs, all_losses, classes, the_class):
    the_color = ["r", "g", "b", "black"]
    Y = [[] for i in range(8)]
    for i in range(epochs):
        tmp = 0
        for j in range(3):
            Y[j].append(all_losses[i][j][the_class])
            tmp += all_losses[i][j][the_class]
        Y[3].append(tmp)
    x = [i for i in range(epochs)]
    x1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
    the_name = []
    for i in epoch_ap:
        L, name = deal_table(i)
        the_name = name
        for j in range(4):
            Y[4 + j].append(L[(j + 1) % 4][the_class])
    # for i in range(4):
    # tmp = Y[i][0]
    # for j in range(len(Y[i])):
    # if tmp == 0.0:
    # Y[i][j] = 0
    # else:
    # Y[i][j] = 1 - (tmp - Y[i][j]) / tmp
    # for i in range(4):
    # print(Y[i])
    fig = plt.figure()

    scale_name = ["Small", "Middle", "Large", "ALL"]
    ax1 = fig.add_subplot(111)
    for i in range(1):
        # for i in range(4):
        ax1.plot(x,
                 Y[i],
                 label=scale_name[i] + "_loss",
                 color=the_color[i],
                 linestyle="--")
    ax1.set_ylabel('the rest of loss')
    ax1.set_title(classes[the_class])

    ax2 = ax1.twinx()  # this is the important function
    for i in range(4, 8):
        ax2.plot(x1,
                 Y[i],
                 label=scale_name[i - 4] + "_ap",
                 color=the_color[i - 4],
                 linestyle="-")
    ax2.set_ylabel('the AP')
    ax2.set_xlabel('Epoch')
    plt.legend()
    # print(classes[the_class])
    # plt.savefig("pic/classes/" + classes[the_class] + ".png")
    # plt.savefig("pic/classes_change/" + classes[the_class] + ".png")
    plt.savefig("pic/small_losses/" + classes[the_class] + ".png")
示例#2
0
文件: 1.py 项目: Don98/Loss
def draw_20_ap(epochs, classes):
    x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
    Y = [[] for i in range(len(classes) + 1)]
    the_name = []
    for i in epoch_ap:
        L, name = deal_table(i)
        the_name = name
        for j in range(len(the_name)):
            Y[j].append(L[0][j])
    for i in range(len(the_name)):
        plt.plot(x, Y[i], label=the_name[i], color=all_color[i])
    plt.xlabel("Epoch")
    plt.ylabel("AP")
    plt.title("20 classes AP")
    plt.legend()
    plt.show()
示例#3
0
文件: 1.py 项目: Don98/Loss
def draw_scale_ap(epochs, classes, scale):
    x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
    Y = [[] for i in range(len(classes) + 1)]
    the_name = []
    for i in epoch_ap:
        L, name = deal_table(i)
        the_name = name
        for j in range(len(the_name)):
            Y[j].append(L[scale][j])
    # print(len(x))
    # print(len(Y[0]))
    for i in range(len(the_name)):
        plt.plot(x, Y[i], label=the_name[i], color=all_color[i])
    plt.xlabel("Epoch")
    plt.ylabel("AP")
    scale_name = ["Small", "Middle", "Large"]
    plt.title(scale_name[scale - 1] + " AP")
    plt.legend()
    plt.show()
示例#4
0
文件: 1.py 项目: Don98/Loss
def each_loss_num_ap(epochs, classes):
    # f = open("each_loss_num_ap.csv","w")
    f = open("each_loss_num_nosort_ap.csv", "w")
    f.write("类别,尺度,loss")
    for i in range(epochs):
        f.write(",Epoch" + str(i))
    f.write("\n")
    result = np.zeros((3, 20))
    result = [list(i) for i in list(result)]
    for i in range(3):
        for j in range(20):
            result[i][j] = [0.0 for i in range(epochs)]
    import copy
    # result_num = np.zeros((3,20))
    result_num = copy.deepcopy(result)
    each_iter = []
    for epoch in range(epochs):
        for j in range(2501):
            bbox, clss_loss_num, cls_loss, reg_loss_num, reg_loss, all_loss = read_file(
                path + str(epoch) + os.sep + filename_part + str(j) + ".txt")
            scale = []
            each_classes = []
            for k in bbox:
                size = np.abs(k[2] - k[0]) * np.abs(k[3] - k[1])
                if size <= 1024:
                    scale.append(0)
                elif size <= 9216:
                    scale.append(1)
                else:
                    scale.append(2)
                each_classes.append(classes[int(k[4])])
                result_num[scale[-1]][int(k[4])][epoch] += 1
            for k in range(len(cls_loss)):
                result[scale[cls_loss[k][1]]][int(
                    bbox[cls_loss[k][1]][4])][epoch] += cls_loss[k][2][int(
                        bbox[cls_loss[k][1]][4])] + sum(reg_loss[k][1])
    scale_name = ["S", "M", "L"]
    for i in range(len(classes)):
        for j in range(3):
            the_num = 0
            if sum(result_num[j][i]) != 0:
                the_num = sum(result[j][i]) / sum(result_num[j][i])
            write_content = [
                classes[i] + "," + scale_name[j],
                sum(result_num[j][i]), result_num[j][i], result[j][i], i, j
            ]
            each_iter.append(write_content)
    Y = []
    the_name = []
    for i in epoch_ap:
        L, name = deal_table(i)
        the_name = name
        Y.append(L)
    # each_iter.sort(key = lambda x :x[1])
    # for i in each_iter[::-1]:
    for i in each_iter:
        f.write(i[0])
        f.write(",AP:,")
        for j in range(epochs - 1):
            f.write("," + str(Y[j][i[-1] + 1][i[-2]]))
        f.write("\n")
        f.write(",,loss:")
        for j in range(epochs):
            f.write("," + str(i[-3][j]))
        f.write("\n")
        f.write(",,loss变化:")
        for j in range(epochs):
            if i[-3][0] == 0:
                f.write("," + str(0))
            else:
                f.write("," + str(1 - (i[-3][0] - i[-3][j]) / i[-3][0]))
        f.write("\n")
        f.write(",,mean:")
        for j in range(epochs):
            if i[-4][j] != 0:
                f.write("," + str(i[-3][j] / i[-4][j]))
            else:
                f.write("," + str(0))
        f.write("\n")
    f.close()
示例#5
0
文件: 1.py 项目: Don98/Loss
def all_bbox_num_sort(epochs, classes):
    f = open("16bbox_num_nosort_loss.csv", "w")
    # f = open("16bbox_num_sort_loss.csv","w")
    # f = open("16bbox_sort_loss.csv","w")
    f.write("类别,尺度,Bboxs数量,样本数量,loss,平均,剩余loss")
    for i in range(1, epochs):
        f.write(",Epoch" + str(i))
    f.write("\n")
    result = np.zeros((3, 20))
    result_num = np.zeros((3, 20))
    each_iter = []
    sample_num = np.zeros((3, 20))
    start_loss = np.zeros((3, 20))
    tmp_loss = np.zeros((3, 20))
    end_loss = np.zeros((3, 20))
    for epoch in range(epochs):
        for j in range(2501):
            bbox, clss_loss_num, cls_loss, reg_loss_num, reg_loss, all_loss = read_file(
                path + str(epoch) + os.sep + filename_part + str(j) + ".txt")
            scale = []
            each_classes = []
            part_sample_num = np.zeros((3, 20))
            for k in bbox:
                size = np.abs(k[2] - k[0]) * np.abs(k[3] - k[1])
                if size <= 1024:
                    scale.append(0)
                elif size <= 9216:
                    scale.append(1)
                else:
                    scale.append(2)
                each_classes.append(classes[int(k[4])])
                result_num[scale[-1]][int(k[4])] += 1
                part_sample_num[scale[-1]][int(k[4])] = 1
            sample_num += part_sample_num
            for k in range(len(cls_loss)):
                result[scale[cls_loss[k][1]]][int(
                    bbox[cls_loss[k][1]][4])] += cls_loss[k][2][int(
                        bbox[cls_loss[k][1]][4])] + sum(reg_loss[k][1])
                if epoch == 0:
                    start_loss[scale[cls_loss[k][1]]][int(
                        bbox[cls_loss[k][1]][4])] += cls_loss[k][2][int(
                            bbox[cls_loss[k][1]][4])] + sum(reg_loss[k][1])
                if epoch == epochs - 1:
                    end_loss[scale[cls_loss[k][1]]][int(
                        bbox[cls_loss[k][1]][4])] += cls_loss[k][2][int(
                            bbox[cls_loss[k][1]][4])] + sum(reg_loss[k][1])
    # print(end_loss)
    # print(start_loss)
    the_pos = (start_loss == 0)
    end_loss = 1 - (start_loss - end_loss) / start_loss
    end_loss[the_pos] = 0.0
    scale_name = ["S", "M", "L"]
    for i in range(len(classes)):
        for j in range(3):
            the_num = 0
            if sample_num[j][i] != 0:
                the_num = result[j][i] / sample_num[j][i]
            write_content = [
                classes[i] + "," + scale_name[j] + "," +
                str(result_num[j][i]) + "," + str(sample_num[j][i]) + "," +
                str(result[j][i]) + "," + str(the_num) + "," +
                str(end_loss[j][i]), result_num[j][i], result[j][i], i, j
            ]
            each_iter.append(write_content)
    Y = []
    the_name = []
    for i in epoch_ap:
        L, name = deal_table(i)
        the_name = name
        Y.append(L)
    # each_iter.sort(key = lambda x :x[1])
    # for i in each_iter[::-1]:
    for i in each_iter:
        f.write(i[0])
        for j in range(epochs - 1):
            f.write("," + str(Y[j][i[-1] + 1][i[-2]]))
        f.write("\n")
    f.close()