Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pedro-r-marques/keras-opt
Keras Scipy optimize interface
https://github.com/pedro-r-marques/keras-opt
keras optimization scipy
Last synced: 3 days ago
JSON representation
Keras Scipy optimize interface
- Host: GitHub
- URL: https://github.com/pedro-r-marques/keras-opt
- Owner: pedro-r-marques
- License: apache-2.0
- Created: 2019-03-20T14:38:41.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-18T17:28:29.000Z (almost 4 years ago)
- Last Synced: 2024-01-30T00:41:23.929Z (10 months ago)
- Topics: keras, optimization, scipy
- Language: Python
- Size: 42 KB
- Stars: 15
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# keras-opt
Keras Scipy optimize interface
Interface between keras optimizers and scipy.optimize. It is used to run full
batch optimization rather than mini-batch stochastic gradient descent. It
is applicable to factorization of very sparse matrices where stochastic
gradient descent is not able to converge.Example usage:
```python
#%%
# Model definition (linear regression)
from keras_opt import scipy_optimizer
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, InputLayermodel = Sequential()
model.add(InputLayer(input_shape=(4,)))
model.add(Dense(1, use_bias=False))
model.compile(loss='mse')#%%
# Generate test dataimport 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
```