Python 板


LINE

各位前輩,由於問題描述的太過簡略,容小弟詳細說明 其程式碼來自 YOLO 的 predict result decoder,source code 如下 : netout #為Numpy NDarray anchors #為 Numpy DNarray obj_thresh #為 Float32 其數值為 0.6 net_h ,netw #為 int 其數值為 416 def decode_netout(netout, anchors, obj_thresh, net_h, net_w): grid_h, grid_w = netout.shape[:2] nb_box = 3 netout = netout.reshape((grid_h, grid_w, nb_box, -1)) nb_class = netout.shape[-1] - 5 boxes = [] netout[..., :2] = _sigmoid(netout[..., :2]) netout[..., 4:] = _sigmoid(netout[..., 4:]) netout[..., 5:] = netout[..., 4][..., np.newaxis] * netout[..., 5:] netout[..., 5:] *= netout[..., 5:] > obj_thresh for i in range(grid_h*grid_w): row = i / grid_w col = i % grid_w for b in range(nb_box): # 4th element is objectness score objectness = netout[int(row)][int(col)][b][4] if(objectness.all() <= obj_thresh): continue # first 4 elements are x, y, w, and h x, y, w, h = netout[int(row)][int(col)][b][:4] x = (col + x) / grid_w # center position, unit: image width y = (row + y) / grid_h # center position, unit: image height w = anchors[2 * b + 0] * np.exp(w) / net_w # unit: image width h = anchors[2 * b + 1] * np.exp(h) / net_h # unit: image height # last elements are class probabilities classes = netout[int(row)][col][b][5:] box = BoundBox(x-w/2, y-h/2, x+w/2, y+h/2, objectness, classes) boxes.append(box) return boxes 而小弟追蹤該 function 時發現該 objectness 為 float32 (請看截圖) 而無法理解 該ojbectness為何會有 .all() 這個方法, 並且用來判斷 bool ? 一直無法理解這個問題 故上來請教前輩們這個疑惑 謝謝大家幫忙 圖片如下 : https://photos.app.goo.gl/rbsPt91WBi1FcuvN6 --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 117.56.58.151 (臺灣)
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Python/M.1624335041.A.C7D.html
1F:推 penut85420: 我在想你的那個float32應該是來自numpy.float32 06/22 12:25
2F:→ penut85420: 我觀察前面的變數名稱只有顯示ndarray 06/22 12:26
3F:→ penut85420: 而不是numpy.ndarray 06/22 12:26
4F:→ penut85420: 所以我推測了這個float32應該是numpy.float32 06/22 12:27
5F:→ penut85420: 而numpy.float32也確實有.all()這個方法 06/22 12:27
6F:推 penut85420: 關於bool判斷,我在GitHub上找到一個Issue也在談論 06/22 12:33
7F:→ penut85420: https://git.io/Jn14v 06/22 12:33
8F:→ chengreg: 是的。該文的問題跟小弟的一模一樣 謝謝前輩 06/22 12:50
9F:推 s0914714: 所以你上篇回應不太精準 這就是numpy的東西 06/22 13:42
10F:→ s0914714: 一般大家講的Python指的是原生的Python 06/22 13:43
11F:→ chengreg: 這也是小弟頭痛的地方,有時候會搞不清楚該數值從何而來 06/22 13:44
12F:→ chengreg: 但經由penut前輩小弟找到issue並且該作者說這是一個bug 06/22 13:45
13F:→ chengreg: 該bug也已修正,小弟會再多注意是否研讀新版本,謝謝大家 06/22 13:49
14F:推 poototo: IDE 好像都不會顯示更多,是numpy的float32沒錯 06/22 15:46
15F:→ poototo: x = np.float32(-1) 可以用x.all() 06/22 15:46
16F:→ poototo: array.item(n) 跟 array[n] 回傳的類型也不一樣喔 06/22 15:48
17F:推 penut85420: 我推薦檢測特定變數的型態還是用內建的type()比較好 06/22 16:31
18F:→ chengreg: 謝謝前輩提供經驗! 06/22 20:21
19F:→ chengreg: 該問題小弟已全數了解並成功解決 06/22 20:29
20F:→ chengreg: 再次謝謝各位前輩! 06/22 20:29
21F:→ RumiManiac: 原生型別也不是叫做 float32 啊... 06/23 05:07
22F:→ chengreg: 是。我會多注意行型別的。謝謝前輩提醒 06/23 12:34







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:iOS站內搜尋

TOP