R,keras:TypeError:传递给参数'shape'的值具有DataType float32不在允许值列表中:int32,int64

时间:2017-04-25 13:55:34

标签: r tensorflow anaconda keras

我正在尝试在R中创建一些神经网络,在张量流anaconda环境中使用张量流上的kerasR包。

在这里你可以看到我的设置:

library(reticulate)
use_condaenv("tensorflow", required = TRUE)

py_config()

结果是:

python:         C:\Users\Miguel\Anaconda3\envs\tensorflow\python.exe
libpython:      C:/Users/Miguel/Anaconda3/envs/tensorflow/python35.dll
pythonhome:     C:\Users\Miguel\ANACON~1\envs\TENSOR~1
version:        3.5.3 |Continuum Analytics, Inc.| (default, Feb 22 2017, 21:28:42) [MSC v.1900 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:\Users\Miguel\ANACON~1\envs\TENSOR~1\lib\site-packages\numpy
numpy_version:  1.12.1

python versions found: 
 C:\Users\Miguel\Anaconda3\envs\tensorflow\python.exe
 C:\Users\Miguel\ANACON~1\python.exe

这是我的代码:

library(kerasR)
mod <- Sequential()
mod$add(Dense(units = 200, input_shape = 13))

会抛出此错误消息:

Error in py_call_impl(callable, dots$args, dots$keywords) : 
  TypeError: Value passed to parameter 'shape' has DataType float32 not in list of allowed values: int32, int64

Detailed traceback: 
  File "c:\users\miguel\documents\github\keras\keras\models.py", line 430, in add layer(x)
  File "c:\users\miguel\documents\github\keras\keras\engine\topology.py", line 558, in __call__ self.build(input_shapes[0])
  File "c:\users\miguel\documents\github\keras\keras\layers\core.py", line 827, in build constraint=self.kernel_constraint)
  File "c:\users\miguel\documents\github\keras\keras\legacy\interfaces.py", line 88, in wrapper return func(*args, **kwargs)
  File "c:\users\miguel\documents\github\keras\keras\engine\topology.py", line 391, in add_weight weight = K.variable(initializer(shape), dtype=dtype, name=name)
  File "c:\users\miguel\documents\github\keras\keras\initializers.py", line 208, in __call__ dtype=dtype, seed=self.seed)
  File "c:\users\miguel\documents\github\keras\keras\backend\tensorflow_backend.py", l

不幸的是,我找不到这个R / kerasR / tensrflow / anaconda设置的建议。我们将非常感谢您的帮助。

我的会话信息:

R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=Spanish_Spain.1252  LC_CTYPE=Spanish_Spain.1252   
[3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C                  
[5] LC_TIME=Spanish_Spain.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] kerasR_0.4.1   reticulate_0.7

loaded via a namespace (and not attached):
[1] tools_3.3.2  Rcpp_0.12.10 knitr_1.15  

2 个答案:

答案 0 :(得分:1)

错误说在tensorflow代码的某处,你试图为参数赋值float值,但是该参数不能是float,它应该是int,

答案 1 :(得分:0)

我也在努力解决这个问题,并试图在https://github.com/statsmaths/kerasR/issues/13的支持线程中提出的一些黑客行为没有成功。

最终工作的解决方案完全放弃了kerasR库,而是由RStudio团队支持keras

它似乎提供了相同的功能,具有实际工作的优点;另外,鉴于它似乎得到了RStudio项目的支持,可能有更好的机会保持在目前正在使用Python中的DL框架看来不可避免的持续依赖性地狱。