我在 Google Colab 中使用包含您的 Gist 的代码执行了代码,并遵循了 link 中的 Tensorflow Profiler 文档。
您应该检查您的 TensorFlow、Tensorboard 和 TensorFlow Profiler 版本。
按照文档中的说明运行此 sn-p 以确保 最新 版本。
# Uninstall twice to uninstall both the 1.15.0 and 2.1.0 version of TensorFlow and TensorBoard.
!pip uninstall -y -q tensorflow tensorboard
!pip uninstall -y -q tensorflow tensorboard
!pip install -U -q tf-nightly tb-nightly tensorboard_plugin_profile
当您运行 Tensorboard 并且仍然看不到 Profile 选项卡时,您可以执行此 sn-p 然后重新启动 Tensorboard(终止进程)。
!pip install -U tensorboard_plugin_profile
这是我添加的几个代码 sn-ps。
根据文档。
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from datetime import datetime
from packaging import version
import os
# Imports
from tensorflow.keras.applications import MobileNetV2
from tensorflow.keras.layers import *
from tensorflow.keras.models import *
import matplotlib.pyplot as plt
%matplotlib inline
import tensorflow as tf
print(tf.__version__) # This should return 2.2.0-dev20200408 (as of date ) or higher
检查 GPU 是否可用。
device_name = tf.test.gpu_device_name()
if not device_name:
raise SystemError('GPU device not found')
print('Found GPU at: {}'.format(device_name))
用于运行 Tensorboard。
# Launch TensorBoard and navigate to the Profile tab to view performance profile
%tensorboard --logdir=logs
如果成功执行,它应该显示接近下图。 (注意:将 Epoch 数减少到 5 以加快训练速度)
希望这会对您有所帮助。
如果需要,我可以编辑并提供完整的 Google Colab Notebook 代码。