为什么Tensor.get_shape()可以在初始化会话之前立即工作?

时间:2017-08-24 00:40:49

标签: tensorflow

如许多TF文档中所示,只有在我们创建sess并执行sess.run()方法时才开始构建图形。

刚才,我测试过:

mockGetUserMedia(function(originalStream) {
  var context = new AudioContext();
  var microphone = context.createMediaStreamSource(originalStream);
  var backgroundMusic = context.createMediaElementSource(document.getElementById("song"));
  var mixedOutput = context.createMediaStreamDestination();
  microphone.connect(mixedOutput);
  backgroundMusic.connect(mixedOutput);

  var stream = mixedOutput.stream;
  originalStream.getVideoTracks().map(function(track) {
    stream.addTrack(track);
  });
  return stream;
});

如此代码中所示,即使我没有创建会话实例,它也会输出特定的Y形状值。

如何理解?谢谢!

1 个答案:

答案 0 :(得分:5)

有“静态形状”和“动态形状”,get_shape()是静态的,只需要图表,tf.shape是动态的,需要会话 - How to understand static shape and dynamic shape in TensorFlow?