google-chrome - 无法使用 Google Colab 上传本地文件
问题描述
尝试将文件上传到 Google Colab 时出现错误。
Upload widget is only available when the cell has been executed in the current browser session.
Please rerun this cell to enable.
---------------------------------------------------------------------------
MessageError Traceback (most recent call last)
<ipython-input-18-1bbed4ac709e> in <module>()
62 from keras.preprocessing import image
63
---> 64 uploaded = files.upload()
65
66 for fn in uploaded.keys():
我的浏览器: Google Chrome,版本 83.0.4103.116(官方版本)(64 位)(在 Windows 10 上)
我发现以前问过两个问题。见下文。但是,这两种解决方案都不适合我。
解决方案
我发现我做错了什么。我试图在 Colab 的同一个单元格中执行一堆脚本。当涉及到 files.upload() 时,它导致了问题。我将该段移动到另一个单元格并执行它。它工作得很好。当你这样做时,看起来 Colab 不喜欢它。
这是我指的代码片段:
# RUNNING THE MODEL
print('RUNNING THE MODEL')
import numpy as np
from google.colab import files
from keras.preprocessing import image
uploaded = files.upload()
for fn in uploaded.keys():
# predicting images
path = '/content/' + fn
img = image.load_img(path, target_size=(300, 300))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
images = np.vstack([x])
classes = model.predict(images, batch_size=10)
print(classes[0])
if classes[0]>0.5:
print(fn + " is a human")
else:
print(fn + " is a horse")
推荐阅读
- javascript - 提交表单和 API 调用竞争后,Bootstrap Spinner 不会停止
- api - 我需要 alphaadvantage 的替代品来查看外汇相对于美元的价格
- ios - 在 Project Navigator 中单击 JSON 文件时 Xcode 冻结(并崩溃)
- numpy - 高维广播和
- c# - 如何在 Swift 中创建 SaS 令牌?
- javascript - 为什么这个变量没有在 javascript 中返回?
- html - 如何使用 Angular 11 预填充 html5 日期选择器
- python - 为什么我不能给我的 pygame 窗口命名或图标?
- r - R列出某个点后在全局环境中创建的所有变量
- python - 在pandas / python中使用group by function来获得总和,具有最大点和对应点的主题的最有效方法是什么