Open mohamedmkamra opened 1 year ago
Hi @mohamedmkamra
How are then you running the model with cppflow? What error you getting?
As far as I can see is a single-input, single-output model, so I don't think it's a multi-input problem.
Actually the number of inputs is technically not 1. X_train is a numpy array with number of rows = ntrainData and number of columns = n_inputs Y_train is a numpy array with number of rows = ntrainData and number of columns = n_outputs This is why I am not sure about this.
ntrainData is the number of dimensions or features of your data?
No, ntrainData is the size of training data ( i.e. number of training samples)
PyTorch models are prepared to take inputs of shape NxD (as yours). With N being number of samples, batch dimension, and D being the dimension of each data point.
Without seeing what are you trying is hard to make a guess.
I am not using PyTorch, I am using tensor flow. I have used tensorflow::keras to train a neural network based on the model above.
def build_model(X_train, d , n ):
n_inputs = X_train.shape[1]
n_outputs = Y_train.shape[1]
model = Sequential()
model.add(Dense(128, input_dim=n_inputs, activation='elu', kernel_regularizer=regularizers.l2(l2=n)))
model.add(Dropout(d))
# model.add(Dense(32, activation='elu', kernel_regularizer=regularizers.l2(l2=n)))
# model.add(Dropout(0))
model.add(Dense(n_outputs))
optimizer = tf.keras.optimizers.Adam( learning_rate=0.001 , beta_1=0.9, beta_2=0.999, epsilon=1e-07, amsgrad=False, name='Adam') # These are the default values
# Smaller learning rate will cause better accuracy, but with higher computational power (larger training time)
model.compile(loss ='mse',
optimizer=optimizer,
metrics=['mae', 'mse'])
return model
The NN model is simple: it has 5 inputs, and the size of training data is roughly 100K samples with every sample consisting of 5 values as inputs and 2 values as outputs.
The number of hidden layers and number of neurons per layer shown here is just for illustration.
Yeah, I meant TensorFlow sorry.
But I don't see how you trying to use cppflow, you only posted Python code. If it's a TensorFlow related issue, it shouldn't be posted here.
The tf model itself is good. It works fine for evaluation when the model files are read in Python.
But when I try to read the model files using cppflow, I get segmentation fault errors: Basically, I tried using the load_model example
int main() {
auto input = cppflow::fill({10, 5}, 1.0f);
cppflow::model model(std::string(MODEL_PATH));
auto output = model(input);
std::cout << output << std::endl;
auto values = output.get_data<float>();
for (auto v : values) {
std::cout << v << std::endl;
}
return 0;
}
Try following this answer on StackOverflow
I am trying to load a model that has multiple inputs and outputs. I followed you example but I keep getting segmentation faults errors. The model is created using the following python code:
and I saved the model using the code:
It should be straight forward using the example that you provided but I keep getting errors. Perhaps I should treat this as a single input and output but the data type would be a tuple or list? Am I missing something?
Thanks