Comments (8)
@AtrCheema you mean with Dropout?
from keract.
Please give more information thanks
from keract.
@philipperemy Thankyou for your response. I want to visualize the output of certain layer in ConvNet while it is being trained. Let's suppose if second last layer has 10 neurons and last layer has 1 neuron. I want to see 10 values from second last layer while the network is being trained.
from keract.
@AtrCheema Can you show that on a code example? For example is it during fit()?
from keract.
@philipperemy Yes I want during fit. For example following code makes NN to learn add 2 time series. I want to get output of second last layer which has 2 nodes
`
#https://machinelearningmastery.com/how-to-develop-convolutional-neural-network-models-for-time- series-forecasting/
#multivariate data preparation
#multivariate multiple input cnn example
from numpy import array
from numpy import hstack
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dense
from tensorflow.python.keras.layers import Flatten
from tensorflow.python.keras.layers.convolutional import Conv1D
from tensorflow.python.keras.layers.convolutional import MaxPooling1D
#split a multivariate sequence into samples
def split_sequences(sequences, n_steps):
X, y = list(), list()
for i in range(len(sequences)):
# find the end of this pattern
end_ix = i + n_steps
# check if we are beyond the dataset
if end_ix > len(sequences):
break
# gather input and output parts of the pattern
seq_x, seq_y = sequences[i:end_ix, :-1], sequences[end_ix-1, -1]
X.append(seq_x)
y.append(seq_y)
return array(X), array(y)
#define input sequence
dataset_len = 100
is1 = array([i*10+10 for i in range(dataset_len)])
is2 = array([i*10+15 for i in range(dataset_len)])
out_seq = array([is1[i]+is2[i]
for i in range(len(is1))])
#convert to [rows, columns] structure
is1 = is1.reshape((len(is1), 1))
is2 = is2.reshape((len(is2), 1))
out_seq = out_seq.reshape((len(out_seq), 1))
#horizontally stack columns
dataset = hstack((is1, is2,
#is3,is4,is5,is6,is7,is8,is9,
out_seq))
#print('raw input data is : \n{}\n'.format(dataset[0:7]))
#choose a number of time steps
n_steps = 3
#convert into input/output
X, y = split_sequences(dataset, n_steps)
#print('given \n{} we want to predict {}\n'.format(X[0], y[0]))
#model input must have shape [samples, timesteps, features]
#the dataset knows the number of features, e.g. 2
n_features = X.shape[2]
#define model
model = Sequential()
conv1d = Conv1D(filters=64, kernel_size=2, activation='relu', input_shape=(n_steps, n_features))
model.add(conv1d)
mp1d = MaxPooling1D(pool_size=2)
model.add(mp1d)
fl = Flatten()
model.add(fl)
model.add(Dense(50, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(4, activation='relu'))
model.add(Dense(2, activation='relu'))
model.add(Dense(1))
#print('\nCompiling model\n')
model.compile(optimizer='adam', loss='mse')
#plot_model(model, to_file='multivariate_laos.png', show_shapes=True,)
#fit model
model.fit(X, y, epochs=1000, batch_size=None, verbose=0, shuffle=False, steps_per_epoch=None)
##demonstrate prediction
x_input = array([[80, 85], [90, 95], [100, 105]])
x_input = x_input.reshape((1, n_steps, n_features))
yhat = model.predict(x_input, verbose=0)
print(yhat)`
from keract.
At every batch, every epoch, every what? @AtrCheema
from keract.
@philipperemy At every time a 'sample' is evaluated and corresponding loss is calculated. I suppose this requires some modification in fit
method of class Model
in training.py
but I am unable to figure out how.
from keract.
@AtrCheema https://keras.io/callbacks/
This is what you need: on_batch_end
.
from keract.
Related Issues (20)
- Plans to enable eager execution from TF 2.0? HOT 10
- Error when using model.add_loss HOT 5
- Regression CNN HOT 19
- Visualization on image sequence HOT 2
- Layer Import HOT 1
- Keras symbolic input/outputs and layer_names issue HOT 8
- Using an input other than the one provided by the pre-trained model fails. HOT 20
- get_activations: AttributeError when nested=True HOT 6
- Any plans for Pytorch implementation? HOT 2
- Heatmaps - ValueError: X has 20 features, but MinMaxScaler is expecting 1 features as input. HOT 17
- Can not convert a odict_values into a Tensor or Operation HOT 1
- custom loss not working any more
- Example in the README: 'Functional' object has no attribute '_layers' HOT 2
- display_heatmaps() ValueError: X has 28 features, but MinMaxScaler is expecting 1 features as input. HOT 2
- Interaction with submodels? HOT 5
- Trying to use keract.get_activations() for days, keep getting stuck HOT 3
- Implement with GradientTape
- Help with get_activations HOT 4
- display_heatmap error
- Scikit-learn requirement HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keract.