近期keras调试问题

Keras中model.evaluate()

返回了一个2维数组,查阅资料发现是loss value & metrics values 即 loss值和 你选定的指标值(例如,精度accuracy)
https://blog.csdn.net/Rex_WUST/article/details/84995954
而predict输出预测结果
https://blog.csdn.net/DoReAGON/article/details/88552348

Python format 格式化函数

https://www.runoob.com/python/att-string-format.html
这里是python基础,巩固下
Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能。

基本语法是通过 {} 和 : 来代替以前的 % 。

format 函数可以接受不限个参数,位置可以不按顺序。

>>>"{} {}".format("hello", "world")    # 不设置指定位置,按默认顺序
'hello world'

keras 拆分张量(网络层)

https://www.jianshu.com/p/29df4c8f43df
https://blog.csdn.net/lujiandong1/article/details/54936185
使用keras 自带的Lambda函数进行设计。
具体例子如下

  def slices(x, index):
        return x[:,:,index]

    dr = 0.5  # dropout rate (%)
    tap = 8
    input = Input(input_shape,name='input')
    x = input
    x1 =Lambda(slices, arguments={"index": 0}, name="iq0")(x)
    x2 =Lambda(slices, arguments={"index": 1}, name="iq1")(x)

Input 0 is incompatible with layer conv11: expected ndim=3, found ndim=2 错误

进行完tensor拆分后,将拆分出来的两个张量分别送入网络input层,得到的错误。

Input 0 is incompatible with layer conv11: expected ndim=3, found ndim=2

该问题困扰了我一晚上,我以为是我切分的过程或者函数设置有问题。
看了 http://quabr.com/53599357/valueerror-input-0-is-incompatible-with-layer-conv2-1-expected-ndim-4-found-n
以及 https://stackoverflow.com/questions/42657049/keras-valueerror-input-0-is-incompatible-with-layer-convolution2d-11-expected 对我有很深的启发作用。

实际上我原来的tensor的形状(1024,2),在进行拆分后,我的目标是拆成两个(1024,1),结果函数做了个小优化,直接将拆分出来的结果的形状改为(1024),在keras看来就少了一维。
所以我做了一个reshape,解决了这个问题,如下。

    x = input
    x1 =Lambda(slices, arguments={"index": 0}, name="iq0")(x)
    x2 =Lambda(slices, arguments={"index": 1}, name="iq1")(x)
    x1 =Reshape((1024,1))(x1)
    x2 =Reshape((1024,1))(x2)

附(可不看):另外如果要使用LSTM层,也有可能出现这个问题,
https://blog.csdn.net/zds13257177985/article/details/80051543 相当于不要让lstm就输出一个值。

kears拼接-How to concatenate two layers in keras?

https://stackoverflow.com/questions/43196636/how-to-concatenate-two-layers-in-keras/43196972
https://blog.csdn.net/weixin_42442855/article/details/82721338

部分程序:

    added = Concatenate()([x1, x2])
    added = Concatenate()([x, added])

服务器linux杀死进程

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0     16959      C   python2                                    10737MiB |
|    1      3694      C   python3m                                   10765MiB |
|    2      5480      C   python                                     10765MiB |
+-----------------------------------------------------------------------------+
xxn@ubuntu:~$ kill -9 3694
xxn@ubuntu:~$ nvidia-smi
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0     16959      C   python2                                    10737MiB |
|    2      5480      C   python                                     10765MiB |
+-----------------------------------------------------------------------------+
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值