所以我一直在使用 Google Colab 制作笔记本,突然间我收到以下错误。
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-bd6ec74ccf2e> in <module>()
----> 1 from keras.utils import to_categorical
ImportError: cannot import name 'to_categorical' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/__init__.py)
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为它工作得很好,当我重新开始我的会话时,这发生了。我也尝试使用另一个 google 帐户(以防我的帐户设置有问题),但我仍然遇到相同的错误。
这是我用来导入函数的。
from keras.utils import to_categorical
Run Code Online (Sandbox Code Playgroud)
我想知道是否有任何变化,以及是否有其他人遇到同样的问题。谢谢。
我正在尝试使用视觉 keras 可视化我的深度学习模型,但我收到一个我不确定我理解的错误。这是我第一次使用视觉 keras,我不知道该怎么做。举个例子
!pip install visual keras
import visualkeras
import tensorflow as tf
tf.keras.utils.plot_model(model, show_shapes=True)
input = tf.keras.Input(shape=(100,), dtype='int32', name='input')
x = tf.keras.layers.Embedding(output_dim=512, input_dim=10000, input_length=100)(input)
x = tf.keras.layers.LSTM(32)(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
output = tf.keras.layers.Dense(1, activation='sigmoid', name='output')(x)
model = tf.keras.Model(inputs=[input], outputs=[output])
visualkeras.layered_view(model, legend=True, draw_volume=False)
Run Code Online (Sandbox Code Playgroud)
错误看起来像这样TypeError: 'int' object is not iterable。任何帮助都感激不尽。
我正在尝试使用 Google Colab 上的 Flask 渲染 html 模板,但虽然它看起来很简单,但我无法这样做。这就是我正在做的:
from flask_ngrok import run_with_ngrok
from flask import Flask, render_template , request
from google.colab import drive
drive.mount('/content/gdrive')
app = Flask(__name__)
run_with_ngrok(app)
@app.route('/')
def home():
return render_template('/content/gdrive/MyDrive/test/test.html')
if __name__ == '__main__':
app.run()
Run Code Online (Sandbox Code Playgroud)
我的 html 文件看起来像这样(它只是一个测试文件)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Talk to the bot</title>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我收到内部服务器错误。这是错误的完整输出:
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production …Run Code Online (Sandbox Code Playgroud)