Bonjour,

Je refais un tuto (T. Neveu, Youtube, 2018, "Réseaux à convolution: Chien vs Chat" )
pour faire un réseau de neurones convolutif en vue de reconnaitre des photos de chat vs chien.

Lors du tuto, le code suivant...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import glob
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
import os
import random
 
 
targets = []
features = []
 
files = glob.glob('train/*.jpg')
random.shuffle(files)
 
for file in files[:500]:
    features.append(np.array(Image.open(file).resize((75, 75))))
    target = [1, 0] if 'cat' in file else [0, 1]
    targets.append(target)
 
features = np.array(features)
targets = np.array(targets)
 
print('Shape features', features.shape)
print('Shape targets', targets.shape)
...retournait :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
Shape features (500, 75, 75, 3)
Shape targets (500, 2)
Chez moi, ce jour, ca donne un "warning deprecation".
<ipython-input-11-56ef4bbfee92>:20: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
features = np.array(features)
et une erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
ValueError    Traceback (most recent call last)
<ipython-input-11-56ef4bbfee92> in <module>
     18     targets.append(target)
     19 
---> 20 features = np.array(features)
     21 targets = np.array(targets)
     22 
 
ValueError: could not broadcast input array from shape (75,75,3) into shape (75,75)
Le warning ne s'affiche plus si j'ajoute un dtype aux lignes 20 et 21,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
features = np.array(features, dtype=float)
targets = np.array(targets, dtype=float)
Pourriez vous m'aider à comprendre quoi faire pour ne plus avoir ce problème de brodcasting?