代码地址:https://github.com/zhiyongc/Graph_Convolutional_LSTM
数据集地址:https://drive.google.com/drive/folders/1E-rRwIPFDZcTWc7zZDcyd4XbIgecW97q
环境搭建
作者给出的环境是Python3.6.1和Pytorch0.4.1,但是Pytorch0.4.1太老了,因此查询Python和Pytorch和CUDA匹配的版本并经过安装验证后选择Python3.7.0和CUDA1.7.1,但是仍然有很多因为版本带来的问题,只能逐一修改。
配置Python3.7.0
和Pytorch1.7.1
环境
conda create -n Python3.7.0andPyTorch1.7.1 python=3.7.0
activate Python3.7.0andPyTorch1.7.1
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
调试步骤:
- 在
Code_V1
同级目录下新建文件夹Data
,把下载好的数据放进去。 - 在
Train_Validate.py
中69行下注释data = 'inrix'
,取消data = 'loop'
的注释。 - 运行
Main.py
文件,运行之后报错
报错:
- 报错(1)
- 问题:
NameError: name 'train_dataloader' is not defined
- 解决:把93行
train_dataloader, valid_dataloader, test_dataloader, max_speed = PrepareDataset(speed_matrix)
取消注释。
- 问题:
- 报错(2):
- 问题:
IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed
,该问题有三处。 - 解决:定位到
Train_Validate.py
的108
和110
行、210
行和212
行、301
行和312
行,把.cpu().numpy()[0]
中的[0]去掉
- 问题:
- 报错(3):
- 问题:
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
- 解决:参考: 链接,改源码
File "D:\Anaconda3\Lib\site-packages\torch\_tensor.py"
,将
- 问题:
def __array__(self, dtype=None):
if has_torch_function_unary(self):
return handle_torch_function(Tensor.__array__, (self,), self, dtype=dtype)
if dtype is None:
return self.numpy()
else:
return self.numpy().astype(dtype, copy=False)
改为:
def __array__(self, dtype=None):
if has_torch_function_unary(self):
return handle_torch_function(Tensor.__array__, (self,), self, dtype=dtype)
if dtype is None:
return self.cpu().numpy()
else:
return self.cpu().numpy().astype(dtype, copy=False)
- 报错(4)
- 问题:
IndexError: invalid index of a 0-dim tensor. Use
tensor.item()in Python or
tensor.item()in C++ to convert a 0-dim tensor to a number
,该问题有三处。 - 解决:参考:链接,定位到
Train_Validate.py
的531
和533
行、595
行和597
行、654
行和656
行,把np.around([loss_l1.data[0]]
和np.around([loss_mse.data[0]]
改成np.around([loss_l1.item()]
和np.around([loss_mse.item()]
- 问题:
- 报错(5)
- 问题:
torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 6.00 GiB total capacity; 12.58 GiB already allocated; 0 bytes free;
- 解决:显存不足,把
batch_size
改小,改为10
- 问题:
- 搭建环境遇到的问题
最初搭建的是Python3.6.1
conda create -n Python3.6.1andPyTorch0.4.1 python=3.6.1
报错:
Solving environment: failed PackagesNotFoundError: The following packages are not available from current channels: - python=3.6.1
原因:当前使用的是conda的官方源,其中没有3.6.1
版本的python
,添加源后再创建环境。
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud//pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
进入Python3.6.1andPyTorch0.4.1
环境
activate Python3.6.1andPyTorch0.4.1
安装PyTorch0.4.1
,作者使用的0.4.1
太低了!!!,在链接中查询适合的pytorch版本为1.7
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
报错:
ERROR: Package 'torch' requires a different Python: 3.6.1 not in '>=3.6.2'
安装3.6.2还是有版本问题,于是使用Python3.7.0