Hi,
I want to feed a CNN with vectors or matrices based on the result of some feature extraction methods like GLCM, Haralick, etc. How can I configure it?
Hi,
I want to feed a CNN with vectors or matrices based on the result of some feature extraction methods like GLCM, Haralick, etc. How can I configure it?
Have a look at this post.
Briefly, as a mini-example:
import torch
conv = torch.nn.Conv2d(3, 16, 1)
desired_weight = np.random.randn(16, 3, 1, 1) # initiating with something random for illustration
conv.weight = torch.nn.Parameter(torch.Tensor(desired_weight))
This will set the weights (but not the biases exercise left to the reader) to your custom desired_weight
.
If you’d like to freeze these layers during subsequent training (for example you want to use these precise features but you do want to train a downstream classifier) you can do this:
for param in conv.parameters():
param.requires_grad = False
Hope this helps!
Andrei