ورود

View Full Version : خطا به data



samira22
یک شنبه 03 مهر 1401, 10:31 صبح
با سلام.
من از کد زیر استفاده می کنم :




# Define data loaders.
train_loader = tf.data.Dataset.from_tensor_slices((x_train, y_train))
validation_loader = tf.data.Dataset.from_tensor_slices((x_val, y_val))


batch_size = 2
# Augment the on the fly during training.
train_dataset = (

train_loader.shuffle(len(x_train))
.map(train_preprocessing)
.batch(batch_size)
.prefetch(2)
)
# Only rescale.
validation_dataset = (
validation_loader.shuffle(len(x_val))
.map(validation_preprocessing)
.batch(batch_size)
.prefetch(2)
)









model = Net()
optimizer = optim.Adam(model.parameters(), lr=0.001)
loss_func = nn.NLLLoss()


epochs = 20
loss_list = []


model.train()
for epoch inrange(epochs):
total_loss = []
for batch_idx, (data, target) inenumerate(train_loader):
#batch_idx,

optimizer.zero_grad()
# Forward pass
output = model(data)
# Calculating loss
loss = loss_func(output, target)
# Backward pass
loss.backward()
# Optimize the weights
optimizer.step()

total_loss.append(loss.item())
loss_list.append(sum(total_loss)/len(total_loss))
print('Training [{:.0f}%]\tLoss: {:.4f}'.format(
100. * (epoch + 1) / epochs, loss_list[-1]))







و error زیر را دریافت می کنم:

TypeError Traceback (most recent call last)
<ipython-input-33-505edb0b4bd3> (https://localhost:8080/#) in <module>
14 optimizer.zero_grad()
15 # Forward pass
---> 16 output = model(data)
17 # Calculating loss
18 loss = loss_func(output, target)





/usr/local/lib/python3.7/dist-packages/torch/nn/modules/conv.py (https://localhost:8080/#) in _conv_forward(self, input, weight, bias)
452 _pair(0), self.dilation, self.groups)
453 return F.conv2d(input, weight, bias, self.stride,
--> 454 self.padding, self.dilation, self.groups)
455
456 def forward(self, input: Tensor) -> Tensor:

TypeError: conv2d() received an invalid combination of arguments - got (tensorflow.python.framework.ops.EagerTensor, Parameter, Parameter, tuple, tuple, tuple, int), but expected one of:
* (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
didn't match because some of the arguments have invalid types: (!tensorflow.python.framework.ops.EagerTensor!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)
* (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)
didn't match because some of the arguments have invalid types: (!tensorflow.python.framework.ops.EagerTensor!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)






لطفا راهنمایی بفرمایید.
با تشکر