I have written the following generator function. In order to use class weights, with this generator, I receive an error when I use the following commands
training_generator=image_generator(partition['train'], labels, bat_siz )
counter = Counter(training_generator.classes)
Error: AttributeError: 'generator' object has no attribute 'classes'
Generator function
def image_generator(list_IDs, label_file, batch_size ):
a=np.arange(0,len(list_IDs),1)
a_hat=a
while True:
batch_path=np.random.choice(a_hat,size = batch_size,replace=False)
list_IDs_temp = [list_IDs[k] for k in batch_path]
batch_input = []
batch_output = []
# Read in each input, perform preprocessing and get labels
for i, ID in enumerate(list_IDs_temp):
inp = get_input(ID )
out_label = get_output(ID,label_file )
batch_input += [ inp ]
batch_output += [ out_label ]
# Return a tuple of (input, output) to feed the network
batch_x = np.array( batch_input )
batch_y = np.array( batch_output )
rem_sample=np.setdiff1d(a_hat,batch_path)
a_hat=rem_sample
if len(rem_sample)<1:
a_hat=a
del batch_path,list_IDs_temp
yield( np.asarray(batch_x), to_categorical(batch_y, num_classes=2) )
Could someone tell how to deal with customized generator function. Thanks in advance
Could someone tell how to deal with customized generator function. Thanks in advance