Tensorboard 显示空白页(拒绝从 'http://localhost:6006/index.js' 执行脚本,因为它的 MIME 类型)
Tensorboard is showing a blank page (Refused to execute script from 'http://localhost:6006/index.js' because its MIME type)
尝试打开 tesnorflow 时,我只看到一个空白页面:
这是它在 Firefox 中的样子:
我在 chrome 控制台中收到错误消息:
Refused to execute script from 'http://localhost:6006/index.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
在 firefox 控制台中,我收到错误消息:
The resource from “http://localhost:6006/index.js” was blocked due to MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff)
和
Loading failed for the <script> with source “http://localhost:6006/index.js”.
我试过了:
Unable to open Tensorboard in browser
我在控制台输入:
tensorboard --logdir=runs --bind_all
tensorboard --logdir=./runs --bind_all
tensorboard --logdir=./runs/ --bind_all
tensorboard --logdir=./runs --host localhost --port 6006
tensorboard --logdir=./runs --host localhost
tensorboard --logdir=./runs --port 6006 --bind_all
我有张量板版本:2.1.0
我这样生成数据:
train_set = torchvision.datasets.FashionMNIST(
root="./data/FashionMNIST",
train=True,
download=True,
transform=transforms.Compose([
transforms.ToTensor()
])
)
train_loader = torch.utils.data.DataLoader(train_set, batch_size=1000)
tb = SummaryWriter()
network = Network()
images, labels = next(iter(train_loader))
grid = torchvision.utils.make_grid(images)
tb.add_image("image", grid)
tb.add_graph(network, images)
tb.close()
我遵循了这个教程:TensorBoard with PyTorch - Visualize Deep Learning Metrics
报告了类似的错误和解决方案 here。
显然这与 windows 注册表中的某些问题有关。根据评论,这似乎是解决方案
In my case following procedure solved the problem:
- windows + r and regedit
- [your computer]\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.js
- Change content type from 'text/plain' to 'application/javascript'
如果您不能或不想更改 windows 注册表来修复它(因为它需要一些您可能没有的权限),您唯一的其他选择是直接在mimetypes 库模块。
它通常在 C:\python38\Lib\mimetypes.py
处找到,但您可以通过 运行 命令行中的以下命令找到它的位置:
python -c "import mimetypes; print(mimetypes.__file__)"
打开打印的文件(如果不是本地 python 安装,您可能需要管理员权限)并找到 def guess_type(...):
行,在我的版本中是在行 97
和在函数的开头添加以下行(在我的例子中是 L116
和 L117
):
if (isinstance(url, str) and url[-3:] == '.js'):
return 'application/javascript', None
保存后,return到命令行检查它是否有效:
python -c "import mimetypes; print(mimetypes.guess_type('index.js'))"
请注意,此 'hard-coding' 并不总是最佳选择,因为当您更新 python 版本时, mimetypes.py
将与此 'fix' 一起删除,但它很有用例如,在学校计算机上使用本地 python 安装时。
如果你想了解更多关于这个的讨论issue at the tensorboard repository。
尝试打开 tesnorflow 时,我只看到一个空白页面:
这是它在 Firefox 中的样子:
我在 chrome 控制台中收到错误消息:
Refused to execute script from 'http://localhost:6006/index.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
在 firefox 控制台中,我收到错误消息:
The resource from “http://localhost:6006/index.js” was blocked due to MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff)
和
Loading failed for the <script> with source “http://localhost:6006/index.js”.
我试过了:
Unable to open Tensorboard in browser
我在控制台输入:
tensorboard --logdir=runs --bind_all
tensorboard --logdir=./runs --bind_all
tensorboard --logdir=./runs/ --bind_all
tensorboard --logdir=./runs --host localhost --port 6006
tensorboard --logdir=./runs --host localhost
tensorboard --logdir=./runs --port 6006 --bind_all
我有张量板版本:2.1.0 我这样生成数据:
train_set = torchvision.datasets.FashionMNIST(
root="./data/FashionMNIST",
train=True,
download=True,
transform=transforms.Compose([
transforms.ToTensor()
])
)
train_loader = torch.utils.data.DataLoader(train_set, batch_size=1000)
tb = SummaryWriter()
network = Network()
images, labels = next(iter(train_loader))
grid = torchvision.utils.make_grid(images)
tb.add_image("image", grid)
tb.add_graph(network, images)
tb.close()
我遵循了这个教程:TensorBoard with PyTorch - Visualize Deep Learning Metrics
报告了类似的错误和解决方案 here。
显然这与 windows 注册表中的某些问题有关。根据评论,这似乎是解决方案
In my case following procedure solved the problem:
- windows + r and regedit
- [your computer]\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.js
- Change content type from 'text/plain' to 'application/javascript'
如果您不能或不想更改 windows 注册表来修复它(因为它需要一些您可能没有的权限),您唯一的其他选择是直接在mimetypes 库模块。
它通常在 C:\python38\Lib\mimetypes.py
处找到,但您可以通过 运行 命令行中的以下命令找到它的位置:
python -c "import mimetypes; print(mimetypes.__file__)"
打开打印的文件(如果不是本地 python 安装,您可能需要管理员权限)并找到 def guess_type(...):
行,在我的版本中是在行 97
和在函数的开头添加以下行(在我的例子中是 L116
和 L117
):
if (isinstance(url, str) and url[-3:] == '.js'):
return 'application/javascript', None
保存后,return到命令行检查它是否有效:
python -c "import mimetypes; print(mimetypes.guess_type('index.js'))"
请注意,此 'hard-coding' 并不总是最佳选择,因为当您更新 python 版本时, mimetypes.py
将与此 'fix' 一起删除,但它很有用例如,在学校计算机上使用本地 python 安装时。
如果你想了解更多关于这个的讨论issue at the tensorboard repository。