Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added predict API #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion spkeras/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def convert(self, mdl,x_train,thresholding=0.5,scaling_factor=1,method=0,timeste
new_mdl['config']['output_layers'] = [[inbound_nodes, 0, 0]]
new_mdl = json.dumps(new_mdl)
new_model = model_from_json(new_mdl,
custom_objects={'SpikeActivation':SpikeActivation})
custom_objects={'SpikeActivation':SpikeActivation})
input_shape = model.layers[0].input_shape


Expand Down Expand Up @@ -408,6 +408,22 @@ def evaluate(self,x_test,y_test,timesteps=256,thresholding=0.5,scaling_factor=1,
_x_test = x_test*fix if fix > 0 else np.floor(x_test*self.timesteps)
return self.model.evaluate(_x_test,y_test)

def predict(self, features, timesteps=256, thresholding=0.5, scaling_factor=1,
spike_ext=0, noneloss=False, sf=None, fix=0):
import numpy as np
self.timesteps = timesteps
self.thresholding = thresholding
self.scaling_factor = scaling_factor
self.spike_ext = spike_ext
self.noneloss = noneloss
self.model = self.chts_model(timesteps=timesteps,thresholding=thresholding,
scaling_factor=scaling_factor,
spike_ext=spike_ext,noneloss=noneloss,sf=sf)

self.get_config()
_features = features*fix if fix > 0 else np.floor(features*self.timesteps)
return self.model.predict(features)

def chts_model(self,timesteps=256,thresholding=0.5,scaling_factor=1,spike_ext=0,noneloss=False,sf=None):
#method: 0:threshold norm 1:weight norm
from tensorflow.keras.models import Sequential, model_from_json
Expand Down