我想跟踪张量板上的梯度。然而,由于会话中运行的语句是不是一个东西了和write_grads的说法tf.keras.callbacks.TensorBoard是depricated,我想知道如何跟踪梯度的培训期间Keras或tensorflow 2.0。
我目前的方法是为此目的创建一个新的回调类,但没有成功。也许其他人知道如何完成这种高级的东西。
为测试创建的代码如下所示,但会独立于将梯度值打印到控制台或张量板而遇到错误。
import tensorflow as tf
from tensorflow.python.keras import backend as K
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu', name='dense128'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation='softmax', name='dense10')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
class GradientCallback(tf.keras.callbacks.Callback):
console = True
def on_epoch_end(self, epoch, logs=None):
weights = [w for w in self.model.trainable_weights if 'dense' in w.name …Run Code Online (Sandbox Code Playgroud) 我正在尝试为简化的 Java 语言运行我自制的编译器,但是我总是以分段错误告终。目标是构建一个抽象的语法树。我还尝试使用 valgrind 进行调试,但看起来该工具在我的 PC 上存在一些有关 bison 和 flex 的问题。请帮我。
Lexfile:
%{
#include <stdio.h>
#include "abst.h"
#include "yacc.tab.h"
int yylineno;
int column = 0;
int nesting_comments = 0;
int max_comment_level = 0;
int total_comments_number = 0;
void count() {
int i;
for(i = 0; yytext[i] != '\0'; i++){
if(yytext[i] == '\n')
column = 0;
else if(yytext[i] == '\t')
column += 8 - (column % 8);
else
column++;
}
//printf("%s", yytext); Uncomment this Line for printing the input stream
} …Run Code Online (Sandbox Code Playgroud)