Scipy Keras 的优化器接口
Scipy Optimizer Interface for Keras
我尝试使用 Scipy optimizer
接口的实现来实现 keras
(https://github.com/pedro-r-marques/keras-opt),就像它的例子一样,但我得到了以下错误:
'Sequential' object has no attribute '_configure_steps_per_execution'
我搜索了很多,但找不到任何与 _configure_steps_per_execution
函数相关的内容。
谁能帮帮我?
工作正常。确保你完全填写 requirement.
!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
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)>]
我尝试使用 Scipy optimizer
接口的实现来实现 keras
(https://github.com/pedro-r-marques/keras-opt),就像它的例子一样,但我得到了以下错误:
'Sequential' object has no attribute '_configure_steps_per_execution'
我搜索了很多,但找不到任何与 _configure_steps_per_execution
函数相关的内容。
谁能帮帮我?
工作正常。确保你完全填写 requirement.
!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
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)>]