Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow 在keras'中无tf打印结果;s型拟合_Tensorflow_Keras - Fatal编程技术网

Tensorflow 在keras'中无tf打印结果;s型拟合

Tensorflow 在keras'中无tf打印结果;s型拟合,tensorflow,keras,Tensorflow,Keras,我写了这个损失(用于测试keras中的自定义损失): 然后: model.compile(loss=loss, optimizer=keras.optimizers.Adadelta(), metrics=['accuracy']) model.fit(x_train, y_train) 没有tf。打印结果: Epoch 1/12 60000/60000 [==============================] - 12s 1

我写了这个损失(用于测试keras中的自定义损失):

然后:

model.compile(loss=loss, 
              optimizer=keras.optimizers.Adadelta(),
              metrics=['accuracy'])
model.fit(x_train, y_train)
没有tf。打印结果:

Epoch 1/12 
60000/60000 [==============================] - 12s 198us/step - loss: 25.3197 - acc: 0.9384 - val_loss: 5.6927 - val_acc: 0.9857
Epoch 2/12
60000/60000 [==============================] - 11s 187us/step - loss: 8.7803 - acc: 0.9798 - val_loss: 4.6938 - val_acc: 0.9888

为什么?

我想你在Jupyter笔记本上运行这个。打印到呼叫Jupyter笔记本的终端。看看有没有输出

请参见手册页的蓝色注释

根据以下Evgeniya的评论:您可以编写自己的版本来打印所需的数据(代码):


我以前见过这个。从python命令行运行py文件,您将看到tf中的内容。打印()。

我发现

print("foo = " + str(foo.eval()))

(其中foo是你的张量)工作正常。

在Jupyter笔记本电脑中没有办法做到这一点?你控制了Jupyter笔记本电脑环境吗?我找到了解决方案,需要重定向stderr:没想到,正在寻找Jupyter cell magic。。。不过运气不好。@EvgeniyaTveritinova在调用
tf\u print
时,你传递了什么来代替
op
"""
The default tf.Print op goes to STDERR
Use the function below to direct the output to stdout instead
Usage: 
> x=tf.ones([1, 2])
> y=tf.zeros([1, 3])
> p = x*x
> p = tf_print(p, [x, y], "hello")
> p.eval()
hello [[ 0.  0.]]
hello [[ 1.  1.]]
"""
def tf_print(op, tensors, message=None):
    def print_message(x):
        sys.stdout.write(message + " %s\n" % x)
        return x

    prints = [tf.py_func(print_message, [tensor], tensor.dtype) for tensor in tensors]
    with tf.control_dependencies(prints):
        op = tf.identity(op)
    return op
print("foo = " + str(foo.eval()))