127 lines
3.2 KiB
Plaintext
127 lines
3.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"source": "!pip install tensorboard",
|
|
"id": "add52c783768e27a",
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-06-20T09:23:44.953818Z",
|
|
"start_time": "2025-06-20T09:23:44.941696Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"%load_ext tensorboard\n",
|
|
"%tensorboard --logdir runs --host 0.0.0.0 --port 6006"
|
|
],
|
|
"id": "6d148c29e2c0fbbe",
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"The tensorboard extension is already loaded. To reload it, use:\n",
|
|
" %reload_ext tensorboard\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Reusing TensorBoard on port 6006 (pid 414), started 0:24:42 ago. (Use '!kill 414' to kill it.)"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"<IPython.core.display.HTML object>"
|
|
],
|
|
"text/html": [
|
|
"\n",
|
|
" <iframe id=\"tensorboard-frame-42c02cf9641fd4a7\" width=\"100%\" height=\"800\" frameborder=\"0\">\n",
|
|
" </iframe>\n",
|
|
" <script>\n",
|
|
" (function() {\n",
|
|
" const frame = document.getElementById(\"tensorboard-frame-42c02cf9641fd4a7\");\n",
|
|
" const url = new URL(\"/\", window.location);\n",
|
|
" const port = 6006;\n",
|
|
" if (port) {\n",
|
|
" url.port = port;\n",
|
|
" }\n",
|
|
" frame.src = url;\n",
|
|
" })();\n",
|
|
" </script>\n",
|
|
" "
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"execution_count": 12
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"id": "initial_id",
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"ExecuteTime": {
|
|
"end_time": "2025-06-20T09:23:36.713794Z",
|
|
"start_time": "2025-06-20T09:23:32.977971Z"
|
|
}
|
|
},
|
|
"source": [
|
|
"from torch.utils.tensorboard import SummaryWriter\n",
|
|
"import numpy as np\n",
|
|
"\n",
|
|
"# 创建一个SummaryWriter对象\n",
|
|
"writer = SummaryWriter()\n",
|
|
"\n",
|
|
"for n_iter in range(100):\n",
|
|
" writer.add_scalar('Loss/train', np.random.random(), n_iter)\n",
|
|
" writer.add_scalar('Loss/test', np.random.random(), n_iter)\n",
|
|
" writer.add_scalar('Accuracy/train', np.random.random(), n_iter)\n",
|
|
" writer.add_scalar('Accuracy/test', np.random.random(), n_iter)\n",
|
|
"\n",
|
|
"img = np.zeros((3, 100, 100))\n",
|
|
"img[0] = np.arange(0, 10000).reshape(100, 100) / 10000\n",
|
|
"img[1] = np.arange(0, 10000).reshape(100, 100) / 10000\n",
|
|
"\n",
|
|
"writer.add_image('my_image', img, 0)\n",
|
|
"writer.close()"
|
|
],
|
|
"outputs": [],
|
|
"execution_count": 11
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 2
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython2",
|
|
"version": "2.7.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|