1. For a given array, to take a specific value, the other is set to 0, such pytorch segmentation results contain a plurality of classes, taking only a particular class, do?
#classp = [0,1,2,2,3,0,5,2]这样,后面box,score,mask与之对应
ids = torch.where(classp==0)#选择人类别
classp = classp[ids]
box = box[ids]
score = score[ids]
mask = mask[ids[0], :]
Similar can be simpler
#classp = [0,1,2,2,3,0,5,2]这样,后面box,score,mask与之对应
ids = (classp==0)#选择人类别
classp = classp[ids]
box = box[ids]
score = score[ids]
mask = mask[ids, :]
2. pytorch the inference stage, how to ensure that the model is no gradient information?
Use with torch.no_grad (), modified
with torch.no_grad():
cudnn.fastest = True
torch.set_default_tensor_type('torch.cuda.FloatTensor')
print('yolact loading model...', end='')
net = Yolact()
net.load_weights(config.yolact['model_path'])
net.eval()
print(' Done.')
self.net = net.cuda()
self.net.detect.use_fast_nms = True
self.net.detect.use_cross_class_nms = False
3. How to numpy array into pytorch tensor, in conversion to the cuda
torch.from_numpy(np_array).cuda().float()
How 4.vs code debugging inside a file? How to join the tuning parameters, many args? How to use python conda environment? How to specify debug working directory?
1) through a graphical interface operation, generating launch.json
2) Editing added args: [ "- thresh = 0.5", "--cuda"
3)加入pythonPath:"/home/silva/anaconda3/envs/py372/bin/python"
4)加入cwd:"/home/silva/work"
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"pythonPath": "/home/silva/anaconda3/envs/py372/bin/python",
"cwd": "${fileDirname}",
"args": [
"--trained_model=weights/yolact_resnet50_54_800000.pth",
"--score_threshold=0.15",
"--top_k=15",
"--video_multiframe=4",
"--video=0"
]
}
]
}
5. numpy array passed as parameters are passed by reference, or a copy transfer?
Had often wrong, the original is passed by reference. Inside the function, modify the array, then calls the function of the array will be modified.
def abc(arr): arr = np.zeros((3,3))
Call a = np.ones ((3,3)), then the abc (a), after the execution, print (a) How much? constant
If def abc (arr): arr + = 3, abc (a) after the execution? An increase of 3
If def abc (arr): arr [1] [1] = 34, abc (a) after performing? a corresponding element 34 becomes
Reference https://stackoverflow.com/questions/11585793/are-numpy-arrays-passed-by-reference