microsoft / CNTK

Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit
https://docs.microsoft.com/cognitive-toolkit/
Other
17.5k stars 4.28k forks source link

CNTK 2.1 + keras example deep_dream.py #2538

Open pmfcdb opened 6 years ago

pmfcdb commented 6 years ago

Hi,

When I try to run this example "deep_dream.py" from :

https://github.com/fchollet/keras/tree/master/examples

I get this error: erro

Variable 'Constant('_keras_learning_phase', [], [])' SetValue(): 'source' shape '[1]' differs 'destination' shape '[]'. [CALL STACK]

CNTK::Variable:: SetValue

  • CNTK::Constant:: SetValue
  • PyInit__cntk_py
  • PyCFunction_Call
  • PyEval_GetFuncDesc
  • PyEval_EvalFrameEx
  • PyEval_GetFuncDesc (x2)
  • PyEval_EvalFrameEx (x2)
  • PyFunction_SetAnnotations
  • PyObject_Call
  • PyObject_CallFunctionObjArgs
  • PyWrapper_New
  • PyObject_GenericSetAttrWithDict
  • PyType_Ready

Thks, PB

gwli commented 6 years ago

@pmfcdb just change "v = np.float32([value])" -> "v = np.array(np.float32(value))" in your keras\backend\cntk_backend.py.

def set_learning_phase(value):
    global _LEARNING_PHASE
    if value not in {0, 1}:
        raise ValueError('CNTK Backend: Set learning phase '
                         'with value %s is not supported, '
                         'expected 0 or 1.' % value)
    #v = np.float32([value])
    v = np.array(np.float32(value))
    _LEARNING_PHASE.value = v
pmfcdb commented 6 years ago

Hi, thks, it worked, but now I get this error:

Using CNTK backend Selected GPU[0] GeForce GTX 1060 6GB as the process wide default device. Model loaded.

Traceback (most recent call last): File "C:\Users\pbrito\Documents\PythonApplication3\PythonApplication3\PythonApplication3.py", line 88, in

scaling = K.prod(K.cast(K.shape(x), 'float32'))

File "C:\local\Anaconda3-4.1.1-Windows-x86_64\lib\site-packages\keras\backend\cntk_backend.py", line 615, in prod

axis = _normalize_axis(axis, x)

File "C:\local\Anaconda3-4.1.1-Windows-x86_64\lib\site-packages\keras\backend\cntk_backend.py", line 697, in _normalize_axis

shape = int_shape(x)

File "C:\local\Anaconda3-4.1.1-Windows-x86_64\lib\site-packages\keras\backend\cntk_backend.py", line 314, in int_shape

shape = x.shape

AttributeError: 'list' object has no attribute 'shape' Press any key to continue . . .