简体   繁体   English

我可以向我的RNN / LSTM模型输入字节张量吗?

[英]Can I input a Byte Tensor to my RNN/LSTM model?

I am developing an RNN/LSTM model to which I want to encode the sequence in a ByteTensor to save memory as I am limited to a very tight memory. 我正在开发一个RNN / LSTM模型,我想在ByteTensor中对序列进行编码以节省内存,因为我限于非常紧凑的内存。 However, when I do so, the model returns the following error: 但是,当我这样做时,模型将返回以下错误:

Expected object of scalar type Byte but got scalar type Float for argument #2 'mat2' 标量类型为Byte的预期对象,但参数#2'mat2'的标量类型为Float

So, there seems to be something else that is need to be Byte tensor as well, but I do not know what is it since the console only shows an error at the line: 因此,似乎还有其他需要字节张量的东西,但是我不知道它是什么,因为控制台仅在该行显示错误:

output = model(predictor)

It means that inside the model there are float tensors which are being used to operate on your byte tensor (most likely operands in matrix multiplications, additions, etc). 这意味着在model内部有用于对字节张量进行运算的浮点张量(矩阵乘法,加法等中最有可能的操作数)。 I believe you can technically cast them to byte by executing model.type(torch.uint8) , but your approach will sooner or later fail anyway - since integers are discrete there is no way to used them in gradient calculations necessary for backpropagation. 我相信您可以通过执行model.type(torch.uint8)技术上将其转换为字节,但是您的方法迟早会失败-由于整数是离散的,因此无法在反向传播所需的梯度计算中使用它们。 uint8 values can be used in deep learning to improve performance and memory footprint of inference in a network which is already trained, but this is an advanced technique. uint8值可用于深度学习中,以改善已经经过训练的网络中推理的性能和内存占用,但这是一项高级技术。 For this task your best bet are the regular float32 s. 对于此任务,最好的选择是常规float32 If your GPU supports it, you could also use float16 aka half , though it introduces additional complexity and I wouldn't suggest it for beginners. 如果您的GPU支持它,那么您也可以使用float16 aka half ,尽管它引入了额外的复杂性,我不建议初学者使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用具有固定长度数据的 Keras 进行序列到序列模型(RNN / LSTM)? - How can I do a sequence-to-sequence model (RNN / LSTM) with Keras with fixed length data? 将数据转换为 LSTM Model 的张量 - Transforming data to Tensor for LSTM Model 如何在 TensorFlow 中使用 RNN LSTM model 塑造和训练多列输入和多列 output(多对多)? - How to shape and train multicolumn input and multicolumn output (many to many) with RNN LSTM model in TensorFlow? LSTM堆叠RNN中TimeseriesGenerator的输入形状错误 - Error with input shapes for TimeseriesGenerator in a LSTM stacked RNN RNN LSTM输入形状应该是什么? - What is RNN LSTM input shape supposed to be? Tensorflow动态RNN(LSTM):如何格式化输入? - Tensorflow dynamic RNN (LSTM): how to format input? 我的第一个LSTM RNN损失并未达到预期的降低 - My First LSTM RNN Loss Is Not Reducing As Expected 使用 tensorflow 2.0 运行 RNN LSTM model 时出现错误 - I'm getting an error while running the RNN LSTM model with tensorflow 2.0 您如何使用我在下面构建的 LSTM-RNN model 预测未来值? - How do you predict future values with this LSTM-RNN model I've built below? 为什么我会收到Keras LSTM RNN input_shape错误? - Why do I get a Keras LSTM RNN input_shape error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM