复现MID模型

文章讲述了在使用Python3.8.19和torch1.12.1+cu113版本处理数据时遇到的问题,如数据目录设置错误、numpyfloat别名引发的AttributeError以及IndexError在tensor索引中的应用。给出了针对这些问题的修复建议。
摘要由CSDN通过智能技术生成

0、环境

python 3.8.19
torch 1.12.1+cu113

1、处理数据

运行”process_data.py“,得到”processed_data_noise“文件夹

1、config,dataset设置

1.1设置datasetmain.py中的config、dataset

condig为’configs/baseline.yaml’
dataset从[“eth”, “hotel”, “univ”, “zara1”, “zara2”, “sdd”]中选一个

1.2运行main.py报错找不到文件夹

将baseline.yaml中的”data_dir: processed_data“修改为”data_dir: processed_data_noise“

2、AttributeError: module ‘numpy’ has no attribute ‘float’.

GPT回答:
这个错误消息表明你在使用 np.float,它是 Python 中已经被弃用的别名,代表内置的 float 类型。为了避免这个错误,你应该直接使用 float,而不是 np.float。如果你需要使用 NumPy 的标量类型,可以使用 np.float64。

因此,你可以根据需求将 np.float 替换为 float 或 np.float64。

例如:

将 np.float 替换为 float
x = float(5.0)

或者将 np.float 替换为 np.float64
y = np.float64(5.0)
这样的修改将防止你遇到的 AttributeError 错误。

于是进行修改
scene_graph.py中的

dist_cube = np.zeros((total_timesteps, N, N), dtype=np.float)

修改为

dist_cube = np.zeros((total_timesteps, N, N), dtype=float)
node_attention_mat = np.zeros((N, N), dtype=np.float)

修改为

node_attention_mat = np.zeros((N, N), dtype=
float)

3、IndexError: tensors used as indices must be long, byte or bool tensors

GPT说:
主要错误:张量索引中的 IndexError
当你尝试使用一个张量作为另一个张量的索引时,出现错误 IndexError: tensors used as indices must be long, byte or bool tensors。这表示用作索引的张量不是 PyTorch 允许用于索引的数据类型(即,应该是 long、byte 或 bool 类型)。以下是如何解决这个问题:

检查数据类型:确保用于索引的张量 last_index_per_sequence 是正确的数据类型。如果它不是,你可以显式地将它转换为 long 类型:

last_index_per_sequence = last_index_per_sequence.long()


在这里插入图片描述
中的

last_index_per_sequence = -(first_history_indices + 1)

后增加

last_index_per_sequence = last_index_per_sequence.long()

(536行和616行)

成功运行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值