Cross Validated
2023-10-02 05:40 UTC
By Dkasi
AI-113-20231002-social-media-f73041b8
Creating a CNN model for multi-output prediction where one target variable is categorical, and others are numeric
I want to create a simple CNN model for multi-output prediction. The predicted values are four numeric values (all between 0-1) and one categorical value (4 classes). When I try to create a model using Keras, I cannot predict numeric and categorical values using one model. I use a workaround for a categorical variable, where I one-hot-encode it and predict one-hot-encoded values. What would be the right approach for multi-output prediction, where the predicted values are categorical and numeric; How do I change the code to use the Categorical Cross entropy loss function and argmax to predict the categorical output variable (simultaneously with other numerical output variables)? from tensorflow.keras.utils import to_categorical from tensorflow.keras.preprocessing.image import ImageDataGenerator from tensorflow.keras import layers import tensorflow.keras as keras import pandas as pd def baselineCNNModel(train_df, test_df, OUTPUT_DIR_TRAIN, OUTPUT_DIR_TEST, debug = False): """ Create a baseline CNN model for multi-output prediction. The input is full images (containing one or more road signs). The target prediction values are class labels and bounding box information. """ print("\nrunSimpleModel\n") train_dataset = train_df[['Class Number', 'Center in X', 'Center in Y', 'Width', 'Height', 'Image Filename']] test_dataset = test_df[['Class Number', 'Center in X', 'Center in Y', 'Width', 'Height', 'Image Filename']] train_class_number_labels_one_hot = to_categorical(train_dataset[…
I want to create a simple CNN model for multi-output prediction. The predicted values are four numeric values (all between 0-1) and one categorical value (4 classes). When I try to create a model using Keras, I cannot predict numeric and categorical values using one model. I use a workaround for a categorical variable, where I one-hot-encode it and predict one-hot-encoded values. What would be the right approach for multi-output prediction, where the predicted values are categorical and numeric; How do I change the code to use the Categorical Cross entropy loss function and argmax to predict the categorical output variable (simultaneously with other numerical output variables)? from tensorflow.keras.utils import to_categorical from tensorflow.keras.preprocessing.image import ImageDataGenerator from tensorflow.keras import layers import tensorflow.keras as keras import pandas as pd def baselineCNNModel(train_df, test_df, OUTPUT_DIR_TRAIN, OUTPUT_DIR_TEST, debug = False): """ Create a baseline CNN model for multi-output prediction. The input is full images (containing one or more road signs). The target prediction values are class labels and bounding box information. """ print("\nrunSimpleModel\n") train_dataset = train_df[['Class Number', 'Center in X', 'Center in Y', 'Width', 'Height', 'Image Filename']] test_dataset = test_df[['Class Number', 'Center in X', 'Center in Y', 'Width', 'Height', 'Image Filename']] train_class_number_labels_one_hot = to_categorical(train_dataset[…
Full article content could not be extracted automatically. Read the original below.
Source:
Cross Validated
· stats.stackexchange.com