Conversation
main_gain.py
Outdated
| gain = gain.AttentionGAIN("all-segments-exists", 5, gpu=False) | ||
|
|
||
| loader = il.DatasetLoader.initial() | ||
| train = loader.load_tensors(0, 13, 2000) |
There was a problem hiding this comment.
signature is load_tensors(self, lower_bound=None, upper_bound=None, load_first_segments: int = 10 ** 20)
I guess it was intended to be train = loader.load_tensors(0, 2000, 13) ?
image_loader.py
Outdated
| labels = [] | ||
| # trusted = None | ||
| for idx, i in enumerate(P.labels_attributes): | ||
| segments.append(dct[i].tolist()) |
There was a problem hiding this comment.
using tensor concatenation (torch.cat) would be more readable than converting to list and then back to tensor
| batch_size = labels.shape[0] | ||
| output_cl = self.model(images) | ||
|
|
||
| grad_target = output_cl * class_label |
There was a problem hiding this comment.
Why to compute the gradient during model evaluation?
There was a problem hiding this comment.
looks like this is redudant because in lines bellow:
loss_cl = self.loss_classifier(output_cl, class_label)
loss_cl.backward()
optimizer.step()```
we do the same
classifier.py
Outdated
| output_cl = self.model(images) | ||
|
|
||
| grad_target = output_cl * class_label | ||
| grad_target.backward(gradient=class_label * output_cl, retain_graph=True) |
There was a problem hiding this comment.
Why is the gradient of grad_target used? it certainly affects gradients during training. But what's the point of this operation?
gain.py
Outdated
| return tensor.data.cpu().item() | ||
|
|
||
|
|
||
| def reduce_boundaries(boundaries: int, batch_size=10): |
There was a problem hiding this comment.
You could make this method 1000 times faster with such implementation:
HUGE = -10000
zeros = torch.zeros((batch_size, 1, 224, 224))
zeros[:,:,0:boundaries,:] = HUGE
zeros[:,:,224-boundaries:224,:] = HUGE
zeros[:,:,:,0:boundaries] = HUGE
zeros[:,:,:,224-boundaries:224] = HUGE
return zeros
gain.py
Outdated
| # weights_new_shape = (1, weights.shape[0] * weights.shape[1], weights.shape[2], weights.shape[3]) | ||
| # weights = weights.view(weights_new_shape).unsqueeze(0) | ||
|
|
||
| self._last_grad = self._last_grad # weights |
There was a problem hiding this comment.
What was intended to be there?
There was a problem hiding this comment.
It's not needed here, but Pycharm marked it with yellow color what is annoyed
gain.py
Outdated
| grad_target = output_cl * label | ||
| grad_target[:, ill_index * 2].backward(gradient=label[:, ill_index * 2] * output_cl[:, ill_index * 2], | ||
| retain_graph=True) | ||
| grad_target[:, ill_index * 2 + 1].backward(gradient=label[:, ill_index * 2] * output_cl[:, ill_index * 2], |
There was a problem hiding this comment.
Is it certain that the backward argument should be ill_index2 and not ill_index2+1?
image_loader.py
Outdated
| transforms.ToTensor(), | ||
| ]) | ||
|
|
||
| """normalization = transforms.Compose([ |
There was a problem hiding this comment.
FYI imagenet stats are: transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
gain.py
Outdated
| output_cl = self.model(data) | ||
| # тут раньше была сумма, но не думаю что она нужна в данном случае | ||
| grad_target = output_cl * label | ||
| grad_target[:, ill_index * 2].backward(gradient=label[:, ill_index * 2] * output_cl[:, ill_index * 2], |
There was a problem hiding this comment.
Why gradient is multiplied by output_cl?
… into AustinDoolittle
Using gradient as in original paper
… into AustinDoolittle
No description provided.