Comment puis-je supprimer automatiquement le canal Alpha des images JPG?
J'utilise un code d'apprentissage profond basé sur Pytorch qui nécessite 3 canaux, mais mes images ont 4 canaux. J'ai vu cette réponse mais je ne sais pas comment convertir toutes les images d'un dossier en une image de contrepartie qui n'a pas de canal alpha.
Voici l'erreur que je reçois:
[jalal@goku example]$ python img_to_vec_nearest_neighbors.py
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
return f(*args, **kwds)
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
return f(*args, **kwds)
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
return f(*args, **kwds)
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
return f(*args, **kwds)
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torchvision-0.2.1-py3.6.Egg/torchvision/transforms/transforms.py:188: UserWarning: The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead.
Traceback (most recent call last):
File "img_to_vec_nearest_neighbors.py", line 18, in <module>
vec = img2vec.get_vec(img)
File "../img_to_vec.py", line 43, in get_vec
h_x = self.model(image)
File "/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
File "/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torchvision-0.2.1-py3.6.Egg/torchvision/models/resnet.py", line 139, in forward
File "/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
File "/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 301, in forward
self.padding, self.dilation, self.groups)
RuntimeError: Given groups=1, weight of size [64, 3, 7, 7], expected input[1, 4, 224, 224] to have 3 channels, but got 4 channels instead
Par exemple, comment puis-je exécuter la commande suivante pour toutes les images que j'ai dans un seul dossier? Mes images ont les extensions JPG, JPEG et PNG, mais cela ne vous dérange pas si elles deviennent tous JPG.
convert cat.png -background white -alpha remove cat.jpg
find . -name "*.jpeg" -exec convert "{}" -alpha off "{}" \;
find . -name "*.png" -exec convert "{}" -alpha off "{}" \;
find . -name "*.jpg" -exec convert "{}" -alpha off "{}" \;