Hi, I am trying to get access to the gradient of my image by using this line
data_grad = data[1].grad.data
then I get some error:(
how shall I handle this error?
thanks
for batch_idx, (data, target) in enumerate(train_loader):
target = target if len(target) > 0 else None
if not type(data) in (tuple, list):
data = (data,)
if device:
data = tuple(d.device() for d in data)
if target is not None:
target = target.device()
    data[0],data[1],data[2].requires_grad_(True)
    outputs = model(*data)
    
    if type(outputs) not in (tuple, list):
        outputs = (outputs,)
        
    loss_inputs = outputs
    if target is not None:
        target = (target,)
        loss_inputs += target

    loss_outputs = loss_fn(*loss_inputs)
    loss = loss_outputs[0] if type(loss_outputs) in (tuple, list) else loss_outputs
    optimizer.zero_grad()
    loss.backward()
    data_grad = data[1].grad.data#here I got some error