多层RNN张量流

时间:2016-04-26 14:16:27

标签: python tensorflow

我有两层LSTM网络。 (config.n_input为3,config.n_steps为5)

我认为这可能与我输入的形状有关,但我不确定如何修复它,我尝试更改LSTM的投影,以便它们的输入大小相同,但是没有工作

tensorflow.python.pywrap_tensorflow.StatusNotOK: Invalid argument: Expected size[1] in [0, 0], but got 600
 [[Node: RNN/MultiRNNCell/Cell1/Slice = Slice[Index=DT_INT32, T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](_recv_state_0/_3, RNN/MultiRNNCell/Cell1/Slice/begin, RNN/MultiRNNCell/Cell1/Slice/size)]]

尝试运行时会返回以下错误。

(function() {

  angular.module('myApp', []);

  var uniqueItems = function(data, key) {
    var result = [];

    for (var i = 0; i < data.length; i++) {
      var value = data[i][key];

      if (result.indexOf(value) == -1) {
        result.push(value);
      }

    }
    return result;
  };

   angular.module('myApp').controller("MyCtrl",MyCtrl)

  function MyCtrl($scope, filterFilter) {
    $scope.usePants = {};
    $scope.useShirts = {};
    $scope.useShoes = {};

    $scope.players = [{
      name: 'Bruce Wayne',
      shirt: 'XXL',
      pants: '42',
      shoes: '12'
    }, {
      name: 'Wayne Gretzky',
      shirt: 'XL',
      pants: '38',
      shoes: '10'
    }, {
      name: 'Michael Jordan',
      shirt: 'M',
      pants: '32',
      shoes: '9'
    }, {
      name: 'Rodman',
      shirt: 'XSXL',
      pants: '42',
      shoes: '11'
    }, {
      name: 'Jake Smitz',
      shirt: 'XXL',
      pants: '42',
      shoes: '12'
    }, {
      name: 'Will Will',
      shirt: 'XXLL',
      pants: '42',
      shoes: '12'
    }, {
      name: 'Youasdf Oukls',
      shirt: 'XL',
      pants: '38',
      shoes: '10'
    }, {
      name: 'Sam Sneed',
      shirt: 'XL',
      pants: '38',
      shoes: '10'
    }, {
      name: 'Bill Waxy',
      shirt: 'M',
      pants: '32',
      shoes: '9'
    }, {
      name: 'Javier Xavior',
      shirt: 'M',
      pants: '32',
      shoes: '9'
    }, {
      name: 'Bill Knight',
      shirt: 'M',
      pants: '32',
      shoes: '9'
    }, {
      name: 'One More',
      shirt: 'M',
      pants: '32',
      shoes: '9'
    }, {
      name: 'Player One',
      shirt: 'XXL',
      pants: '42',
      shoes: '11'
    }, {
      name: 'Space Cadet',
      shirt: 'XXL',
      pants: '42',
      shoes: '12'
    }, {
      name: 'Player Two',
      shirt: 'XXXXL',
      pants: '42',
      shoes: '12'
    } {
      name: 'Bill Knight',
      shirt: 'M',
      pants: '32',
      shoes: '9'
    }, {
      name: 'One More',
      shirt: 'M',
      pants: '32',
      shoes: '9'
    }, {
      name: 'Player One',
      shirt: 'XXL',
      pants: '42',
      shoes: '11'
    }, {
      name: 'Space Cadet',
      shirt: 'XXL',
      pants: '42',
      shoes: '12'
    }];

    // Watch the pants that are selected
    $scope.$watch(function() {
      return {
        players: $scope.players,
        usePants: $scope.usePants,
        useShirts: $scope.useShirts,
        useShoes: $scope.useShoes
      }
    }, function(value) {
      var selected;

      $scope.count = function(prop, value) {
        return function(el) {
          return el[prop] == value;
        };
      };

      $scope.pantsGroup = uniqueItems($scope.players, 'pants');
      var filterAfterPants = [];
      selected = false;
      for (var j in $scope.players) {
        var p = $scope.players[j];
        for (var i in $scope.usePants) {
          if ($scope.usePants[i]) {
            selected = true;
            if (i == p.pants) {
              filterAfterPants.push(p);
              break;
            }
          }
        }
      }
      if (!selected) {
        filterAfterPants = $scope.players;
      }

      $scope.shirtsGroup = uniqueItems($scope.players, 'shirt');
      var filterAfterShirts = [];
      selected = false;
      for (var j in filterAfterPants) {
        var p = filterAfterPants[j];
        for (var i in $scope.useShirts) {
          if ($scope.useShirts[i]) {
            selected = true;
            if (i == p.shirt) {
              filterAfterShirts.push(p);
              break;
            }
          }
        }
      }
      if (!selected) {
        filterAfterShirts = filterAfterPants;
      }

      $scope.shoesGroup = uniqueItems($scope.players, 'shoes');
      var filterAfterShoes = [];
      selected = false;
      for (var j in filterAfterShirts) {
        var p = filterAfterShirts[j];
        for (var i in $scope.useShoes) {
          if ($scope.useShoes[i]) {
            selected = true;
            if (i == p.shoes) {
              filterAfterShoes.push(p);
              break;
            }
          }
        }
      }
      if (!selected) {
        filterAfterShoes = filterAfterShirts;
      }

      $scope.filteredPlayers = filterAfterShoes;
    }, true);


    $scope.$watch('filtered', function(newValue) {
      if (angular.isArray(newValue)) {
        console.log(newValue.length);
      }
    }, true);
  }

  angular.module('myApp').filter('count', function() {
    return function(collection, key) {
      var out = "test";
      for (var i = 0; i < collection.length; i++) {
        //console.log(collection[i].pants);
        //var out = myApp.filter('filter')(collection[i].pants, "42", true);
      }
      return out;
    }
  });

  angular.module('myApp').filter('groupBy',
    function() {
      return function(collection, key) {
        if (collection === null) return;
        return uniqueItems(collection, key);
      };
    });

})();

错误消息的任何优秀解释?或者有什么方法可以轻松解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

将num_proj添加到初始状态:

# Tensorflow LSTM cell requires 2x n_hidden length (state & cell)
self.initial_state = tf.placeholder(tf.float32, [None, 2*config.n_hidden + 300], name='state')

这是一个非常不透明的错误,您可以在TF GitHub问题页面上提出它,这可能是一个好主意!