numpy 相關

scipy.sparse.csr_matrix

gt_overlaps in faster rcnn

import scipy.sparse
overlaps = np.zeros((5, 4), dtype=np.float32)
print(overlaps)
print(type(overlaps))
overlaps[3,3] = 1
overlaps = scipy.sparse.csr_matrix(overlaps)
print(overlaps)
print(type(overlaps))
[[0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]]
<class 'numpy.ndarray'>
  (3, 3)	1.0
<class 'scipy.sparse.csr.csr_matrix'>

np.all

roidb[0]['gt_overlaps'] = overlaps
a = overlaps.toarray()
print(a)
a = overlaps.toarray() > -1
print(a)
b = np.all(a, axis=1)
print(b)
[[0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 1.]
 [0. 0. 0. 1.]]
[[ True  True  True  True]
 [ True  True  True  True]
 [ True  True  True  True]
 [ True  True  True  True]
 [ True  True  True  True]]
[ True  True  True  True  True]

axis = 0 = row, axis = 1 = column
np.all(…, axis=1)按行做AND運算,得到一個列向量

np.random

import numpy as np
np.random.seed(3)
blobs = {}
blobs['gt_boxes'] = np.random.randint(0,4,(5,4))
print(blobs['gt_boxes'])
[[2 0 1 3]
 [0 0 0 1]
 [1 3 2 3]
 [1 1 2 1]
 [3 2 0 0]]
np.random.shuffle(blobs['gt_boxes'])
print(blobs['gt_boxes'])
[[1 1 2 1]
 [2 0 1 3]
 [1 3 2 3]
 [0 0 0 1]
 [3 2 0 0]]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章