Question
The paper code encountered a problem similar to the following. After some efforts, it can be regarded as solving this problem.
# import torch
# # print(torch.__version__)
# # print(torch.cuda.is_available())
import multiprocessing
cores = multiprocessing.cpu_count() // 2
def b(xs):
t = temp_num[xs[0]] * 2
return t
def a():
global temp_num
temp_num = [4, 5, 6]
pool = multiprocessing.Pool(cores)
xs = range(3)
batch_result = pool.map(b,xs)
print(batch_result)
def main():
a()
if __name__ == '__main__':
main()
Error:
solve
import multiprocessing
cores = multiprocessing.cpu_count() // 2
def b(x):
xs = x[0]
temp_num = x[1]
t = temp_num[xs] * 2
return t
def a():
global temp_num
temp_num = [4, 5, 6]
pool = multiprocessing.Pool(cores)
xs = range(3)
z =zip(xs,[temp_num] * 3)
result = pool.map(b,z)
print(result)
def main():
a()
if __name__ == '__main__':
main()
Read More:
- Python2 PicklingError: Can‘t pickle <type ‘instancemethod‘>: attribute lookup __builtin__.instanceme
- cpickle.picklingerror can’t pickle type ‘module’ attribute lookup __builtin__.module failed
- RuntimeError: received 0 items of ancdata
- Solution to unbalanced load of multiple cards (GPU’s 0 card is too high) in Python model training (simple and effective)
- Tensorflow in function tf.Print Method of outputting intermediate value
- RuntimeError: cuda runtime error (801) : operation not supported at ..
- RuntimeError:An attempt has been made to start a new process before the……
- Python generates (x, y, z) 3D coordinate sequence
- FCOS No CUDA runtime is found, using CUDA_HOME=’/usr/local/cuda-10.0′
- Error in training yolox: error in importing apex
- 43. Implementation of the shortest code of multiply strings | Java
- Python error type error: ‘range’ object does not support item assignment, solution
- Problem: attributeerror: ‘tensor’ object has no attribute ‘creator’
- Implement Set using Array.
- (Solved) pytorch error: RuntimeError: cuDNN error: CUDNN_STATUS_EXECUTION_FAILED (install cuda)
- Build your own resnet18 network and load torch vision’s own weight
- PyTorch CUDA error: an illegal memory access was encountered
- RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the
- RuntimeError: cuDNN error: CUDNN_ STATUS_ EXECUTION_ Failed solutions
- Python global variables and global keywords