user_123454321:

Can you show the dataset class as well as dataloader ?


this is my datasets class:
“”"""""
def load_data(root_folder):
# These are delcarations of variables that have been used inside the for loop
final_list = list()
labels = list()
# It is iterating through both the categories Fatigue and Non Fatigue
k=0
for cat in category:
# It is taking and processing each file in the folder
for filename in os.listdir(root_folder + cat):
        # Read each file for each category and drop the unnecessary columns
        path = root_folder + cat + '/' + filename
        df = pd.read_csv(path)  # Read the CSV using inbuilt Pandas Function
        # df.drop(index=0, axis=0, inplace=True) # Drop the first row, which contains
        # the units of measurement
        df.columns = ["time", "EEGO1", "EEGO2"]  # Rename the columns for convinience and easy access of
        # the columns
        df.drop(['time'], axis=1, inplace=True)  # Drop the time column, as we are not using it as a
        # time series.
        df.EEGO1 = pd.to_numeric(
            df.EEGO1)  # The data by default is in the form of an object, Convert each row into
        # numeric or floating point
        df.EEGO2 = pd.to_numeric(df.EEGO2)

        print(filename, len(df))

        # Split each file into 6 parts and then make each of them a new row by transposing
        df_split = np.array_split(df, 450)  # Split the dataset into 450 (115200/256=450) different sets.
        for splitted_array in df_split:
            final_list.append(np.array(
                splitted_array))  # After splitting, we are appending all the splitted arrays into 1 single
            # large array of 3 dimentions
            # The following if-else block is used to create labels. We have taken '1' for Fatigue EEG and '0'
            # for Non Fatigue EEG
            # This is not the ideal way to create labels, but this is the most simplest way for this situation
            if cat == 'Fatigue':
                labels.append(0)
            if cat == 'Non Fatigue':
                labels.append(1)
#print (tf.concat(labels),[0,2995200])
#print(type(labels))
# Before returning, convert the lists to arrays and increase the dimentions for being able to feed into the
# Neural Network

return np.array(final_list), np.expand_dims(np.array(labels), axis=1)

if name == “main”:
parser = argparse.ArgumentParser(description=‘VAE MNIST Example’)
parser.add_argument(’–lr’, type=float, default=0.002, metavar=‘N’,
help=‘learning rate for training (default: 0.001)’)
parser.add_argument(’–batch-size’, type=int, default=128, metavar=‘N’,
help=‘input batch size for training (default: 128)’)
parser.add_argument(’–pretrainepochs’, type=int, default=10, metavar=‘N’,
help=‘number of epochs to train (default: 10)’)
parser.add_argument(’–epochs’, type=int, default=10, metavar=‘N’,
help=‘number of epochs to train (default: 10)’)
args = parser.parse_args()
X_train, y_train = load_data(root_folder_train)
X_test, y_test = load_data(root_folder_test)
in_features = 512
out_features = 256

X_train= torch.Tensor(X_train)
X_test=torch.Tensor(X_test)
#X_test = np.reshape(X_test, [-1, 512])
sdae = StackedDAE(input_dim=512, z_dim=10, binary=True,
    encodeLayer=[256,100,10], decodeLayer=[10,100,256], activation="relu",
    dropout=0)
sdae.pretrain(X_train,X_test, lr=args.lr, batch_size=args.batch_size,
              num_epochs=args.pretrainepochs, corrupt=0.3, loss_type="cross-entropy")
sdae.save_model("model/sdae.pt")
sdae.fit(X_train,X_test, lr=args.lr, num_epochs=args.epochs, corrupt=0.3, loss_type="cross-entropy")

“”""""