ValueError: 'The specified size contains a dimension with value <= 0'的解决方法

ValueError: ‘The specified size contains a dimension with value <= 0’的解决方法

在keras下搭建神经网络,运行demo报错。

错误文本:
C:\ProgramData\Anaconda2\python.exe "F:/Program Files (x86)/JetBrains/PycharmProjects/untitled1/CNN3.py"
Using Theano backend.
Traceback (most recent call last):
  File "F:/Program Files (x86)/JetBrains/PycharmProjects/untitled1/CNN3.py", line 43, in <module>
    model = baseline_model()
  File "F:/Program Files (x86)/JetBrains/PycharmProjects/untitled1/CNN3.py", line 37, in baseline_model
    model.add(Dense(128, activation='relu'))
  File "C:\ProgramData\Anaconda2\lib\site-packages\keras\models.py", line 455, in add
    output_tensor = layer(self.outputs[0])
  File "C:\ProgramData\Anaconda2\lib\site-packages\keras\engine\topology.py", line 528, in __call__
    self.build(input_shapes[0])
  File "C:\ProgramData\Anaconda2\lib\site-packages\keras\layers\core.py", line 827, in build
    constraint=self.kernel_constraint)
  File "C:\ProgramData\Anaconda2\lib\site-packages\keras\engine\topology.py", line 364, in add_weight
    weight = K.variable(initializer(shape), dtype=K.floatx(), name=name)
  File "C:\ProgramData\Anaconda2\lib\site-packages\keras\initializers.py", line 205, in __call__
    dtype=dtype, seed=self.seed)
  File "C:\ProgramData\Anaconda2\lib\site-packages\keras\backend\theano_backend.py", line 1969, in random_uniform
    return rng.uniform(shape, low=minval, high=maxval, dtype=dtype)
  File "C:\ProgramData\Anaconda2\lib\site-packages\theano\sandbox\rng_mrg.py", line 1344, in uniform
    size)
ValueError: ('The specified size contains a dimension with value <= 0', (-768, 128))

运行截图如下:
这里写图片描述

解决方式:
修改keras.json文件
这里写图片描述
修改后:
这里写图片描述

这是因为后台不同,我选择的是Theano后台:
Tensorflow ordering (tf):
Shapes are expected to be (size_lines,size_columns,channel)
Theano ordering (th):
Shapes are expected to be (channel,size_lines,size_columns)
If you change the ordering line in the keras.json file to “image_dim_ordering”: “th” it should work. (i’d bet that’s what’s in your Elementary OS keras.json).

评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值