daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. from keras.utils import Sequence
  4. import cv2
  5. import math
  6. import numpy as np
  7.  
  8.  
  9. class MyKerasSequence(Sequence):
  10.  
  11.     def __init__(self, data_list, batch_size):
  12.         self.data_list = data_list
  13.         self.batch_size = batch_size
  14.  
  15.     def __len__(self):
  16.         return math.ceil(len(self.data_list) / self.batch_size)
  17.  
  18.     def __getitem__(self, idx):
  19.         batch = self.data_list[idx * self.batch_size:(idx + 1) * self.batch_size]
  20.  
  21.         x_values = []
  22.         y_values = []
  23.  
  24.         for x, y, t in batch:
  25.             x_values.append(cv2.imread(x))
  26.             y_values.append(y)
  27.  
  28.         return np.array(x_values), np.array(y_values)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top