gpt4 book ai didi

python - 名称错误 : name 'get_ipython' is not defined

转载 作者:IT老高 更新时间:2023-10-28 22:21:09 24 4
gpt4 key购买 nike

我正在开发 Caffe 框架并使用 PyCaffe 接口(interface)。我正在使用通过转换 IPython Notebook 00-classification.ipynb 获得的 Python 脚本来测试 ImageNet 训练模型的分类。但是脚本中的任何 get_ipython() 语句都会出现以下错误:

$ python python/my_test_imagenet.py 
Traceback (most recent call last):
File "python/my_test_imagenet.py", line 23, in <module>
get_ipython().magic(u'matplotlib inline')

在脚本中,我正在导入以下内容:

import numpy as np
import matplotlib.pyplot as plt

get_ipython().magic(u'matplotlib inline')

# Make sure that caffe is on the python path:
caffe_root = '/path/to/caffe/'
import sys
sys.path.insert(0, caffe_root + 'python')

import caffe

plt.rcParams['figure.figsize'] = (10, 10)
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'

import os

# ... Rest of the code...

有人可以帮我解决这个错误吗?

最佳答案

你必须用 ipython 运行你的脚本:

$ ipython python/my_test_imagenet.py

那么 get_ipython 将已经在全局上下文中。

注意:在普通 shell python 中通过 from IPython import get_ipython 将其导入将不起作用,因为您确实需要运行 ipython

关于python - 名称错误 : name 'get_ipython' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32538758/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com