1
$\begingroup$

here I have two different datasets. dataset1 is force plate data and dataset2 is plantar pressure data. dataset1 has shape (2050,2) and dataset2 has shape(2050,89). before doing the training I have normalized the data using minmaxscaler() with a scale of 0-1. after normalizing the data then I did data preprocessing for dataset2 using PCA. here I will reduce the data dimension of the plantar pressure to 12, so the current plantar pressure datashape is (2050.12).

here is my CNN model:

import math
import numpy as np
import pandas as pd
import tensorflow as tf
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler,StandardScaler, RobustScaler
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, r2_score
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM,Activation,Dense,BatchNormalization, LeakyReLU, Conv2D, MaxPooling1D, Conv1D, MaxPooling1D, Flatten, Dropout
from tensorflow.keras.losses import sparse_categorical_crossentropy
from tensorflow.keras.optimizers import Adam, RMSprop, SGD, Adadelta, Adagrad
from sklearn.decomposition import PCA
from sklearn.model_selection import KFold
from numpy import zeros, newaxis
from sklearn.feature_selection import mutual_info_regression
from sklearn.feature_selection import mutual_info_regression,SelectKBest
np.set_printoptions(suppress=True)
%matplotlib inline

Insole = pd.read_csv('1119_Rwalk40s2_list.txt', header=None, low_memory=False)
SIData =  np.asarray(Insole)

df = pd.read_csv('1119_Rwalk40s2.csv', low_memory=False)
columns = ['Fx','Fz']
selected_df = df[columns]
FCDatas = selected_df[:2050]

SmartInsole = np.array(SIData[:2050])
FCData = np.array(FCDatas)

scaler_x = MinMaxScaler(feature_range=(0, 1))
scaler_x.fit(SmartInsole)
xscale = scaler_x.transform(SmartInsole)

scaler_y = MinMaxScaler(feature_range=(0, 1))
scaler_y.fit(FCData)
yscale = scaler_y.transform(FCData)

SIDataPCA = xscale
pca = PCA(n_components=0.99)
pca.fit(SIDataPCA)
SIdata_pca = pca.transform(SIDataPCA)

X_train, X_test, y_train, y_test = train_test_split(SIdata_pca, yscale, test_size=0.10, random_state=2)

model = Sequential()
model.add(Conv1D(64,kernel_size=2,strides=1,padding='same',data_format='channels_last',input_shape=(X_train.shape[1],1)))
model.add(Activation('relu'))
model.add(MaxPooling1D(pool_size = 2, strides = 2))

model.add(Conv1D(32,kernel_size=2,strides=1,padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling1D(pool_size = 2, strides = 2))

model.add(Conv1D(16,kernel_size=2,strides=1,padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling1D(pool_size = 2, strides = 2))

model.add(LSTM(units=16))
model.add(Dense(16,activation='relu'))
model.add(Dense(2, activation='sigmoid'))

model.summary()

model.compile(loss='mse', optimizer=Adam(), metrics=['mse'])

history = model.fit(X_train, y_train, batch_size=64, epochs=50, 
                    validation_data=(X_test, y_test), verbose=2)

model.evaluate(SIdata_pca, yscale)
ypred = model.predict(SIdata_pca)

plt.figure()
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('Model Loss')
plt.ylabel('Loss')
plt.xlabel('epoch')
plt.legend(['train', 'validation'], loc='upper right')
# plt.show()
plt.savefig('Loss Result.png')


x=[]
colors=['red','green','brown','teal','gray','black','maroon','orange','purple']
colors2=['green','red','orange','black','maroon','teal','blue','gray','brown']
for i in range(0,2050):
    x.append(i)
for i in range(0,2):
    plt.figure(figsize=(15,6))
    # plt.figure()
    plt.plot(x,yscale[0:2050,i], color=colors[i])
    plt.plot(x,ypred[0:2050,i], markerfacecolor='none',color=colors2[i])
    plt.title('Result for ResNet Regression')
    plt.ylabel('Y value')
    plt.xlabel('Instance')
    plt.legend(['Real value', 'Predicted Value'], loc='upper right')
    plt.savefig('Regression Result.png'[i])
    plt.show()

below is the model loss plot enter image description here

looking at the training loss model, I don't think there is any indication of overvitting in training, but why can't my model predict high peaks from train data?

prediction results: enter image description here enter image description here

$\endgroup$
3
  • $\begingroup$ Cross posted at reddit.com/r/deeplearning/comments/zrg6fg/… $\endgroup$
    – noe
    Dec 21, 2022 at 14:53
  • $\begingroup$ Have you tried using Mean Absolute Error (MAE) instead of Mean Squared Error (MSE) for your loss? $\endgroup$
    – noe
    Dec 21, 2022 at 15:26
  • $\begingroup$ yes,I have try it. but the predictions still bad $\endgroup$ Dec 22, 2022 at 9:03

1 Answer 1

0
$\begingroup$

I don't know the data content, but here are some tips according to my past experience:

  • The data cycle is around 100 steps. In general, the batch size should be around the data cycle, so that the model learn cycles behavior. Same thing with the LSTM layer: I would have increased its size. 16 neurons could not be enough to memorize a size of 100.
  • I don't know if mixing Conv1D and LSTM could reduce the prediction precision as they are very different: Conv1D memorizes shapes and LSTM memorizes dynamics. Maybe you should try one type first.
  • The peaks seem to be very short (2 or 3 steps). I would suggest a stride of 1 with a kernel size of 3 to ensure that the neurons learn each step.
  • Max Pooling could smooth your data and reduce peak detection because it reduces the values with the closest ones.
  • SGD or AdamW could also have better results than Adam.
  • The model seems to converge too quickly. Lowering the learning rate and increasing the iterations could improve the results.
  • If your data has 50% of values on 0 or 1, maybe you can ignore them and make the training only on the values that matters. This will improve the training results because "useless" data might alter the learning efficiency.
  • You may need more data for training. I can't explain why test data are not that good. In general, good training has good accuracy (around 80%) to have a good generalization. Your situation could be an overfitting one.

In conclusion, the model is a mix of several types of neurons and I'm not able to predict their outcome because their behavior is different. There are probably good reasons to mix them because the loss is quite low. However, I recommend testing one of the proposals above because they could explain why the peaks are not detected very well.

If the parameters are too complex to define, I recommend using a Learned optimizer like Velo.

$\endgroup$
22
  • $\begingroup$ I've follow u're suggestion number 3, I set the stride to 1 in maxpooling then now the model can learn peak. but now the problem is the model can't predict data when I use other data $\endgroup$ Dec 22, 2022 at 9:16
  • $\begingroup$ u can check the new prediction result on these link : imgur.com/a/ZrFaTXY $\endgroup$ Dec 22, 2022 at 9:18
  • $\begingroup$ my model structure now : imgur.com/TdpR0qI $\endgroup$ Dec 22, 2022 at 9:28
  • $\begingroup$ What is the new accuracy value? The result seems not that bad: the peaks are quite well predicted, it is not perfect but it seems better than the previous results. $\endgroup$ Dec 22, 2022 at 9:30
  • $\begingroup$ the model loss plot : imgur.com/X9M0q2r $\endgroup$ Dec 22, 2022 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.