I'm attempting to use your work in my time series classsification pipeline. First of all: Thank you very much for providing the source code under an open source license!
I'm trying to train the model, save it to disk and load it again from another method. This is my code:
x_trainScaledNPArray = np.array(x_trainScaled)
x_testScaledNPArray = np.array(x_testScaled)
y_trainNPArray = np.array(y_train)
y_testNPArray = np.array(y_test)
batch_size = 16
nb_epochs = 1 # 2000
verbose = True
pathToModelCheckpoints = 'myPath/'
pathToModel = 'myPathToModel/'
reduce_lr = keras.callbacks.ReduceLROnPlateau(monitor='loss', factor=0.5, patience=50,min_lr=0.0001)
# model checkpoint
model_checkpoint = keras.callbacks.ModelCheckpoint(filepath=pathToModelCheckpoints, monitor='loss',save_best_only=True)
callbacks=[reduce_lr,model_checkpoint]
input_shape = x_trainScaledNPArray.shape
nb_classes = len(np.unique(y_train))
model = TransferLearningMain.build_model(input_shape, nb_classes, pre_model=None)
TransferLearningMain.train(x_trainScaledNPArray,y_trainNPArray,x_testScaledNPArray,y_testNPArray,batch_size,verbose,nb_epochs,callbacks,pathToModelCheckpoints,pre_model=None)
model.save(pathToModel)
print(x_trainScaledNPArray.shape)
print(x_testScaledNPArray.shape)
model = keras.models.load_model(model_path)
y_pred = model.predict(x_test,batch_size=4)
(18287, 2048)
(347, 2048)
Traceback (most recent call last):
[...]
y_pred = model.predict(x_test,batch_size=4)
File "C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\training.py", line 1727, in predict
tmp_batch_outputs = self.predict_function(iterator)
File "C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\def_function.py", line 889, in __call__
result = self._call(*args, **kwds)
File "C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\def_function.py", line 933, in _call
self._initialize(args, kwds, add_initializers_to=initializers)
File "C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\def_function.py", line 764, in _initialize
*args, **kwds))
File "C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\function.py", line 3050, in _get_concrete_function_internal_garbage_collected
graph_function, _ = self._maybe_define_function(args, kwargs)
File "C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\function.py", line 3444, in _maybe_define_function
graph_function = self._create_graph_function(args, kwargs)
File "C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\function.py", line 3289, in _create_graph_function
capture_by_value=self._capture_by_value),
File "C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\framework\func_graph.py", line 999, in func_graph_from_py_func
func_outputs = python_func(*func_args, **func_kwargs)
File "C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\eager\def_function.py", line 672, in wrapped_fn
out = weak_wrapped_fn().__wrapped__(*args, **kwds)
File "C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\framework\func_graph.py", line 986, in wrapper
raise e.ag_error_metadata.to_exception(e)
ValueError: in user code:
C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\training.py:1569 predict_function *
return step_function(self, iterator)
C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\training.py:1559 step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\distribute\distribute_lib.py:1285 run
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\distribute\distribute_lib.py:2833 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)
C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\distribute\distribute_lib.py:3608 _call_for_each_replica
return fn(*args, **kwargs)
C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\training.py:1552 run_step **
outputs = model.predict_step(data)
C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\training.py:1525 predict_step
return self(x, training=False)
C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\base_layer.py:1013 __call__
input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
C:\Users\myUser\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\input_spec.py:270 assert_input_compatibility
', found shape=' + display_shape(x.shape))
ValueError: Input 0 is incompatible with layer model: expected shape=(None, 18287, 2048), found shape=(None, 2048)
Any ideas to solve this issue are highly appreciated.