import numpy as np
from keras.preprocessing import image
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
%matplotlib inline
path = './test/paper2.png'
img = image.load_img(path, target_size=(150,150))
imgplot = plt.imshow(img)
x = image.img_to_array(img)
img_test = np.expand_dims(x, axis=0)
classes = model.predict(img_test, batch_size=10)
print(classes)
paper, rock, scissors = classes[0]
if paper==1.:
print('paper')
elif rock==1.:
print('rock')
else:
print('scissors')
Run Code Online (Sandbox Code Playgroud)
输出 :
AttributeError: module 'keras.preprocessing.image' has no attribute 'load_img'
Run Code Online (Sandbox Code Playgroud)
当我尝试跑步时。该错误是什么意思以及如何修复它?帮助大家:)我正在努力学习,我不知道哪一个是错的
在 jupyter notebook 中,我可以使用nbextensions配置自动单元计时,结果如下:

我怎样才能在 jupyter实验室中做到这一点?我没有找到任何做类似事情的扩展。
Obs.:我知道用%%time魔法可以达到类似的结果,但我希望它是自动的,所以我不必在每个单元格的开头放置魔法函数。
我正在使用 jupyter notebook,它工作正常,但是当我按 TAB 时,自动完成不起作用。我已经在 StackOverflow 中检查了所有类似的情况,但没有一个解决方案对我有用。我还尝试对 IPython、IPYKernel、Jedi 和 Tornado 进行“pip 升级”,升级工作正常,但问题仍然存在。我在 Firefox、Chrome 和 Edge 中尝试过。当我按 TAB 时,我可以在终端中看到这些错误:
[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
File "c:\users\tomer\appdata\local\programs\python\python39\lib\site-packages\ipykernel\kernelbase.py", line 265, in dispatch_shell
yield gen.maybe_future(handler(stream, idents, msg))
File "c:\users\tomer\appdata\local\programs\python\python39\lib\site-packages\tornado\gen.py", line 762, in run
value = future.result()
File "c:\users\tomer\appdata\local\programs\python\python39\lib\site-packages\tornado\gen.py", line 234, in wrapper
yielded = ctx_run(next, result)
File "c:\users\tomer\appdata\local\programs\python\python39\lib\site-packages\ipykernel\kernelbase.py", line 580, in complete_request
matches = yield gen.maybe_future(self.do_complete(code, cursor_pos))
File "c:\users\tomer\appdata\local\programs\python\python39\lib\site-packages\ipykernel\ipkernel.py", line 356, in do_complete
return self._experimental_do_complete(code, cursor_pos)
File …Run Code Online (Sandbox Code Playgroud) 我试图在ipython的qtconsole中将文本显示为粗体,或颜色,或者可能以斜体显示.
我找到了这个链接:如何在Python中打印粗体文本?,并使用了第一个和第二个答案,但在qtconsole中,只有下划线选项有效.
我尝试:
print '\033[1m' + 'Hello World!' + '\033[0m'
得到:
Hello World!
(没有粗体字).颜色也不起作用.但:
print '\033[4m' + 'Hello World!' + '\033[0m'
得到:
Hello World!
带下划线.
这只是在qtconsole中.在终端中运行ipython,它可以用这种方式做粗体和颜色.
该链接中还有其他选项,使用Python在终端中打印颜色?从它链接,但它们似乎都更复杂,并且使用更复杂的包,而不是我想要做的事情,这只是让qtconsole像普通终端一样显示.
有谁知道发生了什么?这仅仅是qtconsole的限制吗?
我正在尝试使用新的JupyterLab并且无法保存数据.使用香草Jupyter笔记本,我可以双指点击(使用macOS,Safari或Chrome),我得到一个浏览器菜单,允许我复制或保存图形.
在JupyterLab中,此菜单由具有单元格相关功能的笔记本特定的菜单替换,如下所示:
有没有办法可以直接从JupyterLab笔记本中保存一个数字?
我正在尝试创建一个 JupyterLab 扩展,它使用打字稿。
我已经成功添加了包“@types/node”,允许我使用诸如“require(‘http’)”之类的包。
但是,一旦我尝试使用子进程,使用 'require("child_process")' 我在尝试构建扩展时会收到以下错误。
ModuleNotFoundError: Module not found: Error: Can't resolve 'child_process' in '/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/lib' at factory.create (/ home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/webpack/lib/Compilation.js:535:10) 在工厂 (/home/fionn/anaconda3/envs/jupyterlab-ext/ share/jupyter/lab/staging/node_modules/webpack/lib/NormalModuleFactory.js:397:22) 在解析器 (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/webpack/ lib/NormalModuleFactory.js:130:21) 在 asyncLib.parallel (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/webpack/lib/NormalModuleFactory.js:224:22) 在 /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/neo-async/async.js:2825:7 在 /home/fionn/anaconda3/envs/jupyterlab-ext /share/jupyter/lab/staging/node_modules/neo-async/async.js:6886:13 at normalResolver.resolve (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/ webpack/lib/NormalModuleFactory.js:214:25) 在 doResolve (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:184: 12) at hook.callAsync (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5) at _fn0 (eval at create (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:32:10), :15:1) 在解析器。doResolve (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:37:5) 在 hook.callAsync (/home/fionn/anaconda3) /envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5) at _fn0 (eval at create (/home/fionn/anaconda3/envs/jupyterlab-ext) /share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:32:10), :15:1) 在 hook.callAsync (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter /lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)在 _fn0(在创建时评估(/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules) /tapable/lib/HookCodeFactory.js:32:10), :12:1) 在解析器。doResolve (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:42:38) 在 hook.callAsync (/home/fionn/anaconda3) /envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5) …
我尝试通过在〜/ .jupyter/custom /目录中放置一个*.css文件来应用黑暗主题(就像这里一样).这改变了普通jupyter笔记本的主题.但对jupyter实验室外观没有任何影响.我还尝试使用jupyter-theme安装主题,但是唉,jupyter实验室外观没有变化.
有人能指点我的操作指南吗?
我正在使用Jupyterlab我的数据科学研究。使用这个新工具一切正常,但有些进程GridSearchCV有很长的日志,这个结果会污染笔记本。有没有办法像传统的那样激活滚动条来避免这种情况Jupyter notebooks?
我在 jupyter 实验室使用 plotly,但我得到一个空白的输出。我在这里描述了完全相同的问题:plotly.offline.iplot 给出了一个大的空白字段作为其输出 - 为什么?
我尝试了他们在答案中的建议,但没有奏效。
这是我正在使用的代码:
import pandas as pd
import numpy as np
%matplotlib inline
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
cf.go_offline()
df = pd.DataFrame(np.random.randn(100,4), columns='A B C D'.split())
df2 = pd.DataFrame({'category':['A','B','C'], 'values':[32,43,50]})
df.iplot(kind='scatter', x='A',y='B', mode='markers', size=10)
Run Code Online (Sandbox Code Playgroud)
建议之一是将笔记本更改为“受信任”。你知道我如何在 jupyter 实验室中做到这一点吗?
有没有人知道是否有键盘快捷键来切换JupyterLab中的下一个/上一个选项卡(如果有,怎么做)?或者我们是否可以自定义键盘快捷键?
编辑
此youtube显示了如何在JupyterLab中自定义键盘快捷键.我试了一下它对我有用.
jupyter-lab ×10
jupyter ×4
python ×4
ipython ×3
css ×1
keras ×1
node.js ×1
npm ×1
plotly ×1
qtconsole ×1
tensorflow ×1
typescript ×1