第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

何時(shí)使用 multiprocessing.Queue 而不是 multiprocessing.

何時(shí)使用 multiprocessing.Queue 而不是 multiprocessing.

我已經(jīng)嘗試multiprocessing.dummy.Pool過(guò)multiprocessing.Pool多個(gè)深度學(xué)習(xí)項(xiàng)目。我很難理解它multiprocessing.Queue,我不明白它的需要。是否有特殊條件才有用。作為一個(gè)例子,我有以下目標(biāo)函數(shù):def process_detection( det_, dims ,classes):    W = dims[0]    H = dims[1]    classes = classes    boxes = []    confidences=[]    classIDs=[]    classes_pred=[]    for detection in det_:                xcenter, ycenter, width, height = np.asarray([W, H, W, H]) * detection[0:4]                confidence_encoded = detection[5:] # (80,) array                index_class = np.argmax(confidence_encoded) #index of max confidence                confidence = confidence_encoded[index_class] # float value of confidence (probability)                # print(classes)                class_predicted = classes[index_class] # class predicted                if confidence > 0.5:                    if class_predicted == "person":                        print("{} , {:.2f}".format(class_predicted, confidence))                        # continue                        topX = int(xcenter - width/2.)                        topY = int(ycenter - height/2.)                        width = int(width)                        height = int(height)                        confidence = float(confidence)                        bbox = [topX, topY, width, height]                        boxes.append(bbox)                        confidences.append(confidence)                        classIDs.append(index_class)                        classes_pred.append(class_predicted)    return [boxes, confidences, classIDs, classes_pred](池在 while 循環(huán)外部關(guān)閉)。什么時(shí)候需要使用multiprocessing.Queue?我可以使用 multiprocessing.Queue 提高此代碼的效率嗎?
查看完整描述

1 回答

?
收到一只叮咚

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超5個(gè)贊

一般來(lái)說(shuō),沒(méi)有必要(也沒(méi)有用)一起使用 aPool和 a Queue。

a 最有用的方式Pool是在多個(gè)內(nèi)核上并行運(yùn)行具有不同數(shù)據(jù)的相同代碼,以提高吞吐量。也就是說(shuō),使用該map方法及其變體。這對(duì)于每個(gè)數(shù)據(jù)項(xiàng)的計(jì)算獨(dú)立于所有其他數(shù)據(jù)項(xiàng)的情況非常有用。

Queue諸如和 之類的機(jī)制Pipe用于在不同進(jìn)程之間進(jìn)行通信。如果池工作線程中需要aQueue或 a Pipe,則該池工作線程完成的計(jì)算根據(jù)定義不是獨(dú)立的。充其量,這會(huì)降低性能,Pool因?yàn)槌毓ぷ魅藛T可能必須等待數(shù)據(jù)可用。Pool在最壞的情況下,如果所有工作人員都忙于等待數(shù)據(jù)出現(xiàn),它可能會(huì)完全停止Queue。


如何使用Pool

如果您預(yù)計(jì)所有計(jì)算將花費(fèi)大約相同的時(shí)間,則只需使用該map方法即可。當(dāng)所有計(jì)算完成后,這將返回。并且保證返回值與提交數(shù)據(jù)的順序相同。_async(提示:當(dāng)您要做的下一件事是調(diào)用get結(jié)果對(duì)象上的方法時(shí),使用這些方法沒(méi)有什么意義。)

如果某些計(jì)算比其他計(jì)算花費(fèi)的時(shí)間(長(zhǎng)得多),我建議使用imap_unordered. 這將返回一個(gè)迭代器,一旦準(zhǔn)備好,該迭代器將開(kāi)始生成結(jié)果。結(jié)果將按照完成的順序排列,而不是按照提交的順序排列,因此您應(yīng)該向結(jié)果添加一些標(biāo)識(shí)符,以便您能夠知道結(jié)果屬于哪個(gè)輸入數(shù)據(jù)。


查看完整回答
反對(duì) 回復(fù) 2023-08-22
  • 1 回答
  • 0 關(guān)注
  • 188 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)