简体   繁体   English

为什么 Keras model.predict 永远不会在我设置的这个简单的机器学习模型上执行?

[英]Why does Keras model.predict never execute on this simple machine learning model I've setup?

import numpy as np
import keras as ks

model = ks.Sequential([ks.layers.Dense(units=1, input_shape=[1])])
model.compile(optimizer='sgd', loss='mean_squared_error')

xs=np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype = float)
ys=np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype = float)

model.fit(xs, ys, epochs=500)

print(model.predict([10.0]))

The model.predict never executes no matter how long I wait.无论我等待多久,model.predict 都不会执行。 What tests can I do to diagnose the problem?我可以做哪些测试来诊断问题? What questions should I be asking myself to find the issue?我应该问自己什么问题才能找到问题?

Code is ok -- ran in less than 1 second for me.代码没问题——对我来说运行时间不到 1 秒。

6/6 [==============================] - 0s 101us/step - loss: 4.8739e-05
Epoch 500/500

6/6 [==============================] - 0s 115us/step - loss: 4.7737e-05
[[18.979841]]

Process finished with exit code 0

I went back and fixed my build?我回去修复了我的构建?

First I reinstalled tensorflow.首先我重新安装了tensorflow。 My original command was:我原来的命令是:

pip install tensorflow-gpu==2.0

Which I did an install using the following:我使用以下方法进行了安装:

pip install tensorflow

And then I made sure to follow the following steps for Windows.然后我确保遵循以下适用于 Windows 的步骤。

https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM