在调试超分辨率RCAN模型的Pytorch工程时,遇到问题:
ImportError: cannot import name '_worker_manager_loop' from 'torch.utils.data.dataloader'
查看dataloder源码发现问题原因是Pytorch升级到1.0后,dataloder模块中的_worker_manager_loop函数已被移除并由_pin_memory_loop替代,在RCAN-Pytorch工程中解决方案如下:
修改dataloader.py中代码:
self.worker_result_queue = multiprocessing.SimpleQueue()
为
self.worker_result_queue = multiprocessing.Queue()
self.worker_manager_thread = threading.Thread(target=_pin_memory_loop,args=(self.worker_result_queue, self.data_queue, self.done_event, self.pin_memory,maybe_device_id))
self.worker_manager_thread.daemon = True
self.worker_manager_thread.start()
为
self.pin_memory_thread = threading.Thread(target=_pin_memory_loop,args=(self.worker_result_queue, self.data_queue, maybe_device_id, self.done_event))
self.pin_memory_thread.daemon = True
self.pin_memory_thread.start()
原文地址:https://blog.csdn.net/m0_38129460/article/details/88413570