首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Keras的枕优化接口

Keras的枕优化接口
EN

Stack Overflow用户
提问于 2021-04-04 06:21:59
回答 1查看 137关注 0票数 0

我尝试使用Scipy optimizer接口的keras (https://github.com/pedro-r-marques/keras-opt)实现,就像它的例子一样,但我得到了以下错误:

代码语言:javascript
复制
'Sequential' object has no attribute '_configure_steps_per_execution'

我已经搜索了很多,但是找不到任何与_configure_steps_per_execution函数相关的内容。

有谁可以帮我?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-04 10:44:49

效果很好。确保您完全填充了这个要求

代码语言:javascript
复制
!git clone https://github.com/pedro-r-marques/keras-opt.git
import sys 
sys.path.insert(0, "/content/keras-opt")

from keras_opt import scipy_optimizer
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, InputLayer

model = Sequential()
model.add(InputLayer(input_shape=(4,)))
model.add(Dense(1, use_bias=False))
model.compile(loss='mse')

#%%
# Generate test data

import numpy as np

np.random.seed(42)
X = np.random.uniform(size=40).reshape(10, 4)
y = np.dot(X, np.array([1, 2, 3, 4])[:, np.newaxis])

#%%
# Use scipy.optimize to minimize the cost
model.train_function = scipy_optimizer.make_train_function(
            model, maxiter=20)
history = model.fit(X, y)

#%%
# Show weights.
model.trainable_weights
代码语言:javascript
复制
0/Unknown - 0s 0s/step - loss: 2.1390e-11Optimization terminated successfully.
Current function value: 0.000000
Iterations: 6
Function evaluations: 14
Gradient evaluations: 14
1/1 [==============================] - 0s 313ms/step - loss: 2.1390e-11
[<tf.Variable 'dense_1/kernel:0' shape=(4, 1) dtype=float32, numpy=
 array([[1.0000011],
        [2.000016 ],
        [2.9999967],
        [3.9999871]], dtype=float32)>]
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66938537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档