深圳有做网站公司,帮别人做数学题赚钱的网站,仿微信主题wordpress,抖音广告推广怎么收费这是5幅图#xff0c;加上背景共5类。 可以参考这篇文章https://blog.csdn.net/u012426298/article/details/81232386
对于一个多类别图片数据库#xff0c;每个类别都会有一个class frequency, 该类别像素数目除以数据库总像素数目, 求出所有class frequency 的median 值加上背景共5类。 可以参考这篇文章https://blog.csdn.net/u012426298/article/details/81232386
对于一个多类别图片数据库每个类别都会有一个class frequency, 该类别像素数目除以数据库总像素数目, 求出所有class frequency 的median 值除以该类别对应的frequency 得到weight
weightmedian(weights)/weights
#coding:utf-8
from __future__ import print_function
import os
import numpy as np
import cv2
w,h512,512
def find_pic(img,array_list,n_class,pixs):img_sum np.sum(img array_list, axis-1)pix_numbersimg_sum.reshape(-1).tolist().count(3)if pix_numbers:pixspix_numbersn_class1return pixs,n_class
def compute_class(pixs,n_class):return pixs/(n_class*w*h)
def frequence():# images_path ./trainannot_visualimages_path ./visual_examplered np.array([0, 0, 128])yellow np.array([0, 128, 128])green np.array([0, 128, 0])blue np.array([128, 0, 0])back_gro np.array([0, 0, 0])images_list_path [os.path.join(images_path,i) for i in os.listdir(images_path)]n_red0red_pixs0n_yellow 0yellow_pixs 0n_green 0green_pixs 0n_blue 0blue_pixs 0n_back 0back_pixs 0for count,image_path in enumerate(images_list_path):print({}image.format(count))imgcv2.imread(image_path)red_pixs, n_redfind_pic(img,red,n_red,red_pixs)yellow_pixs,n_yellow find_pic(img, yellow,n_yellow,yellow_pixs)green_pixs,n_green find_pic(img, green,n_green,green_pixs)blue_pixs,n_blue find_pic(img, blue,n_blue,blue_pixs)#back_pixs,n_back find_pic(img, back_gro,n_back,back_pixs)print(red_pixs, n_red)print(yellow_pixs,n_yellow)print(green_pixs, n_green)print(blue_pixs, n_blue)print(back_pixs, n_back)f_class_redcompute_class(red_pixs,n_red)f_class_yellow compute_class(yellow_pixs, n_yellow)f_class_green compute_class(green_pixs, n_green)f_class_blue compute_class(blue_pixs, n_blue)f_class_back compute_class(back_pixs, n_back)print(f_class_red,f_class_yellow,f_class_green,f_class_blue,f_class_back)f_class[f_class_red,f_class_yellow,f_class_green,f_class_blue,f_class_back]f_class_mediannp.median(np.array(f_class))print(f_class_median)print(f_class_median/np.array(f_class))
if __name__ __main__:frequence()这样可以保证占比小的class, 权重大于1 占比大的class 权重小于1 达到balancing的效果.