text: import torch
  import os
  import random
  from torch.utils.data import Dataset
  from torch.utils.data import DataLoader
  from torchvision import transforms
  from torchvision.datasets import ImageFolder
  from PIL import Image
  import h5py
  import numpy as np
  import collections
  import numbers
  import math
  import pandas as pd
  
  
  
  class KDD99Loader(object):
      def __init__(self, data_path, mode="train"):
          self.mode=mode
          data = np.load(data_path)
  
          labels = data[:,-1]
          features = data[:,:-1]
          N, D = features.shape
  
          normal_data = features[labels==1]
          normal_labels = labels[labels==1]
  
          N_normal = normal_data.shape[0]
  
          attack_data = features[labels==0]
          attack_labels = labels[labels==0]
  
          N_attack = attack_data.shape[0]
  
          # randIdx = np.arange(N_attack)
          # np.random.shuffle(randIdx)
          N_train = int(N_normal * 0.8)
          N_test = N_normal -N_train
          self.train = normal_data[:N_train]
          self.train_labels =np.zeros(self.train.shape[0])
  
          self.test = normal_data[N_train:]
          self.test_labels = np.zeros(self.test.shape[0])
  
          self.test = np.concatenate((self.test, attack_data[:N_test]),axis=0)
          self.test_labels = np.concatenate((self.test_labels, np.ones(N_test)),axis=0)
          pass
  
      def __len__(self):
          """
          Number of images in the object dataset.
          """
          if self.mode == "train":
              return self.train.shape[0]
          else:
              return self.test.shape[0]
  
  
      def __getitem__(self, index):
          if self.mode == "train":
              return np.float32(self.train[index]), np.float32(self.train_labels[index])
          else:
             return np.float32(self.test[index]), np.float32(self.test_labels[index])
          
  
  def get_loader(data_path, batch_size, mode='train'):
      """Build and return data loader."""
  
      dataset = KDD99Loader(data_path, mode)
  
      shuffle = False
      if mode == 'train':
          shuffle = True
  
      data_loader = DataLoader(dataset=dataset,
                               batch_size=batch_size,
                               shuffle=shuffle)
      return data_loader
  