Я не понимаю разницы между двумя кодами, приведенными ниже:
Есть ли причина, почему это работает:
def evaluer_dessin ():
global result,img
listeimage=[]
for y in matrice:
for x in y:
listeimage.append(x)
img = np.array([listeimage])
afficher_resultat()
try:
Cadre.delete(result)
except:
pass
if evaluerimg:
result=Cadre.create_text(Largeur/2,Hauteur/8,text="c'est un
"+str((prediction[0]+1)%10),font=('', '50'),fill="red")
root.after(300,evaluer_dessin)
def afficher_resultat():
global prediction
prediction = session.run(y_pred_cls,feed_dict={ x : img})
Но этот код здесь не:
def evaluer_dessin ():
global result
listeimage=[]
for y in matrice:
for x in y:
listeimage.append(x)
img = np.array([listeimage])
# this is the line that doesn't work, it says that it cant convert an
# int into a tensor
prediction = session.run(y_pred_cls,feed_dict={ x : img})
try:
Cadre.delete(result)
except:
pass
if evaluerimg:
result=Cadre.create_text(Largeur/2,Hauteur/8,text="c'est un
"+str((prediction[0]+1)%10),font=('', '50'),fill="red")
root.after(300,evaluer_dessin)
Он говорит, что "img" - это int, но его тип - это массив, и самое странное, что когда я использую отдельную функцию для вычисления прогноза, он работает хорошо!
Вот ошибка, показанная для второй программы:
>Traceback (most recent call last):
> File "C:\Users\nicol\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1092, in _run
> subfeed, allow_tensor=True, allow_operation=False)
> File "C:\Users\nicol\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 3490, in as_graph_element
> return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
> File "C:\Users\nicol\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 3579, in >_as_graph_element_locked
> types_str))
>TypeError: Can not convert a int into a Tensor.
>
>During handling of the above exception, another exception occurred:
>
>Traceback (most recent call last):
> File "C:\Users\nicol\Desktop\CNN_exe\programmeCNNexe.py", line 170, in <module>
> evaluer_dessin()
> File "C:\Users\nicol\Desktop\CNN_exe\programmeCNNexe.py", line 123, in >evaluer_dessin
> prediction = session.run(y_pred_cls,feed_dict={ x : img})
> File "C:\Users\nicol\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 929, in run
> run_metadata_ptr)
> File "C:\Users\nicol\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1095, in _run
> 'Cannot interpret feed_dict key as Tensor: ' + e.args[0])
>TypeError: Cannot interpret feed_dict key as Tensor: Can not convert a int into >a Tensor.
>[Finished in 2.1s with exit code 1]
>[shell_cmd: python -u "C:\Users\nicol\Desktop\CNN_exe\programmeCNNexe.py"]
>[dir: C:\Users\nicol\Desktop\CNN_exe]
>[path: C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS >Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\Syst>em32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management >Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine >Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\System32\OpenSSH\;C:\Users\nicol\AppData>\Local\Programs\Python\Python35\Scripts\;C:\Users\nicol\AppData\Local\Programs\>Python\Python35\;C:\Users\nicol\AppData\Local\Programs\Python\Python37\Scripts\>;C:\Users\nicol\AppData\Local\Programs\Python\Python37\;C:\Users\nicol\AppData\>Local\Microsoft\WindowsApps;]