常见的错误及注意项

1.keras报错

Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.

解决办法:将tensorflow版本由1.14.0降为1.5.0后,问题解决。

2.ImageDataGenerator.flow_from_directory()的使用

train_mask_gen=train_img_datagen.flow_from_directory('../data/GlaS/labels/',
                                                     classes=['train'])
#classes中的值为文件夹名,包含所有训练标签(图片格式任意,我的是.bmp)

3. keras报错---需要转化为tensor

ValueError: Layer deeplabv3plus was called with an input that isn't a symbolic tensor. Received type: <class 'numpy.ndarray'>. Full input: [array([[[[.....]]]])]

这个是因为测试的时候要写output = model.predict(input)    .....用多了pytorch,没适应过来
如果用prdict,后期要搭配np.argmax(output,axis=3)
如果用predict_classes则不用

4. keras不接受numpy.array形式的输入,需要转换一下

from keras import backend as K
input = K.cast_to_floatx(input)

input = (B,H,W,C) 跟 pytorch有点差别

5.GPU报错

tensorflow.python.framework.errors_impl.UnknownError: 2 root error(s) found.
  (0) Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
	 [[{{node entry_flow_conv1_1/convolution}}]]
	 [[loss/mul/_6781]]
  (1) Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
	 [[{{node entry_flow_conv1_1/convolution}}]]
0 successful operations.
0 derived errors ignored.



我是在keras中遇到的,不知道是什么原因导致的

解决办法抄了别人的,加在要运行的文件头部,代码如下:

from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession

config = ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)

5. 没有past模块

ImportError: No module named 'past'

解决办法:pip install future

6. 同时打乱两个数组且不打乱对应关系

a = np.arange(0, 10, 1)
b = np.arange(10, 20, 1)
print(a, b)
# result:[0 1 2 3 4 5 6 7 8 9] [10 11 12 13 14 15 16 17 18 19]
state = np.random.get_state()
np.random.shuffle(a)
print(a)
# result:[6 4 5 3 7 2 0 1 8 9]
np.random.set_state(state)
np.random.shuffle(b)
print(b)
# result:[16 14 15 13 17 12 10 11 18 19]

 

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值