使用带Tensorflow的Keras LSTM时输入形状问题

时间:2016-11-23 22:50:39

标签: tensorflow keras lstm

我一直在使用Keras(版本1.1.1)LSTM与Theano作为后端没有任何问题。现在我想切换到Tensorflow(版本0.8.0)并且无法得到一个简单的例子。问题可归结为以下从this Keras-Tensorflow interface tutorial复制的代码段。

    {
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.EntityFrameworkCore": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [ "portable-net45+win8+dnxcore50", "portable-net45+win8" ]
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [ "dotnet5.6", "portable-net45+win8" ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [ "wwwroot", "web.config" ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

执行最后一行时出现以下错误:

  

文件“/home/xxx/local/lib/python2.7/site-packages/Keras-1.1.1-py2.7.egg/keras/engine/topology.py”,第529行,调用           return self.call(x,mask)

     

文件“/home/xxx/local/lib/python2.7/site-packages/Keras-1.1.1-py2.7.egg/keras/layers/recurrent.py”,第227行,正在通话中           input_length = input_shape 1

     

文件“/home/xxx/local/lib/python2.7/site-packages/Keras-1.1.1-py2.7.egg/keras/backend/tensorflow_backend.py”,第1306行,in rnn           axes = [1,0] + list(range(2,len(outputs.get_shape())))   文件“/usr/local/anaconda/lib/python2.7/site-packages/tensorflow/python/framework/tensor_shape.py”,第462行, len           提高ValueError(“不能使用未知等级的Shape长度。”)

     

ValueError:不能使用未知等级的Shape长度。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

你不能像这样混合张量流。 Keras跟张量流的形状分别跟踪张量流的形状。

尝试使用x = Input(shape=(20,64))