اذهب إلى المحتوى
  • 0

عرض مخطط للبيان Graph في تنسرفلو Tensorflow

عامر ابراهيم

السؤال

Recommended Posts

  • 1

يمكننا القيام بذلك من خلال التعليمة التالية:

%tensorboard --logdir logs/train

  لكن يجب أولاً أن نقوم بتحميل الإضافة:

%load_ext tensorboard.notebook

أو في حال ظهر لديك الخطأ التالي:

RuntimeError: Use '%load_ext tensorboard' instead of '%load_ext tensorboard.notebook'.

قم باستخدام:

%load_ext tensorboard.notebook

مثال:

%load_ext tensorboard.notebook
import tensorflow as tf
import numpy as np
logdir = 'logs/'
writer = tf.summary.create_file_writer(logdir)
tf.summary.trace_on(graph=True, profiler=True)
@tf.function
def forward_and_backward(x, y, w, b, lr=tf.constant(0.01)):
    with tf.name_scope('logits'):
        logits = tf.matmul(x, w) + b
    
    with tf.name_scope('loss'):
        loss_fn = tf.nn.sparse_softmax_cross_entropy_with_logits(
            labels=y, logits=logits)
        reduced = tf.reduce_sum(loss_fn)
        
    with tf.name_scope('optimizer'):
        grads = tf.gradients(reduced, [w, b])
        _ = [x.assign(x - g*lr) for g, x in zip(grads, [w, b])]
    return reduced
# الدخل
x = tf.convert_to_tensor(np.ones([1, 2]), dtype=tf.float32)
y = tf.convert_to_tensor(np.array([1]))
# params
w = tf.Variable(tf.random.normal([2, 2]), dtype=tf.float32)
b = tf.Variable(tf.zeros([1, 2]), dtype=tf.float32)
loss_val = forward_and_backward(x, y, w, b)
with writer.as_default():
    tf.summary.trace_export(
        name='NN',
        step=0,
        profiler_outdir=logdir)
%tensorboard --logdir logs/

الخرج:

Untitled.thumb.png.761127fc7be9c4276b66cc4a707d0571.png

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...