小編這次要給大家分享的是Keras如何自定義IOU,文章內(nèi)容豐富,感興趣的小伙伴可以來(lái)了解一下,希望大家閱讀完這篇文章之后能夠有所收獲。
我就廢話不多說(shuō)了,大家還是直接看代碼吧!
def iou(y_true, y_pred, label: int): """ Return the Intersection over Union (IoU) for a given label. Args: y_true: the expected y values as a one-hot y_pred: the predicted y values as a one-hot or softmax output label: the label to return the IoU for Returns: the IoU for the given label """ # extract the label values using the argmax operator then # calculate equality of the predictions and truths to the label y_true = K.cast(K.equal(K.argmax(y_true), label), K.floatx()) y_pred = K.cast(K.equal(K.argmax(y_pred), label), K.floatx()) # calculate the |intersection| (AND) of the labels intersection = K.sum(y_true * y_pred) # calculate the |union| (OR) of the labels union = K.sum(y_true) + K.sum(y_pred) - intersection # avoid divide by zero - if the union is zero, return 1 # otherwise, return the intersection over union return K.switch(K.equal(union, 0), 1.0, intersection / union) def mean_iou(y_true, y_pred): """ Return the Intersection over Union (IoU) score. Args: y_true: the expected y values as a one-hot y_pred: the predicted y values as a one-hot or softmax output Returns: the scalar IoU value (mean over all labels) """ # get number of labels to calculate IoU for num_labels = K.int_shape(y_pred)[-1] - 1 # initialize a variable to store total IoU in mean_iou = K.variable(0) # iterate over labels to calculate IoU for for label in range(num_labels): mean_iou = mean_iou + iou(y_true, y_pred, label) # divide total IoU by number of labels to get mean IoU return mean_iou / num_labels
本文標(biāo)題:Keras如何自定義IOU-創(chuàng)新互聯(lián)
文章路徑:http://jinyejixie.com/article18/pssgp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、品牌網(wǎng)站設(shè)計(jì)、靜態(tài)網(wǎng)站、外貿(mào)建站、網(wǎng)站營(yíng)銷、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容