generator

Is fit_generator in Keras supposed to reset the generator after each epoch?

╄→гoц情女王★ 提交于 2021-02-07 14:22:22
问题 I am trying to use fit_generator with a custom generator to read in data that's too big for memory. There are 1.25 million rows I want to train on, so I have the generator yield 50,000 rows at a time. fit_generator has 25 steps_per_epoch , which I thought would bring in those 1.25MM per epoch. I added a print statement so that I could see how much offset the process was doing, and I found that it exceeded the max when it got a few steps into epoch 2. There are a total of 1.75 million records

Is fit_generator in Keras supposed to reset the generator after each epoch?

人走茶凉 提交于 2021-02-07 14:22:12
问题 I am trying to use fit_generator with a custom generator to read in data that's too big for memory. There are 1.25 million rows I want to train on, so I have the generator yield 50,000 rows at a time. fit_generator has 25 steps_per_epoch , which I thought would bring in those 1.25MM per epoch. I added a print statement so that I could see how much offset the process was doing, and I found that it exceeded the max when it got a few steps into epoch 2. There are a total of 1.75 million records

TypeError: 'generator' object is not callable

天大地大妈咪最大 提交于 2021-02-07 11:23:21
问题 I have a generator defined like this: def lengths(x): for k, v in x.items(): yield v['time_length'] And it works, calling it with for i in lengths(x): print i produces: 3600 1200 3600 300 which are the correct numbers. However, when I call it like so: somefun(lengths(x)) where somefun() is defined as: def somefun(lengths): for length in lengths(): # <--- ERROR HERE if not is_blahblah(length): return False I get this error message: TypeError: 'generator' object is not callable What am I

python generator is too slow to use it. why should I use it? and when?

时光毁灭记忆、已成空白 提交于 2021-02-07 10:24:07
问题 Recently I got question about which one is the most fastest thing among iterator , list comprehension , iter(list comprehension) and generator . and then make simple code as below. n = 1000000 iter_a = iter(range(n)) list_comp_a = [i for i in range(n)] iter_list_comp_a = iter([i for i in range(n)]) gene_a = (i for i in range(n)) import time import numpy as np for xs in [iter_a, list_comp_a, iter_list_comp_a, gene_a]: start = time.time() np.sum(xs) end = time.time() print((end-start)*100) the

python generator is too slow to use it. why should I use it? and when?

旧时模样 提交于 2021-02-07 10:23:33
问题 Recently I got question about which one is the most fastest thing among iterator , list comprehension , iter(list comprehension) and generator . and then make simple code as below. n = 1000000 iter_a = iter(range(n)) list_comp_a = [i for i in range(n)] iter_list_comp_a = iter([i for i in range(n)]) gene_a = (i for i in range(n)) import time import numpy as np for xs in [iter_a, list_comp_a, iter_list_comp_a, gene_a]: start = time.time() np.sum(xs) end = time.time() print((end-start)*100) the

python generator is too slow to use it. why should I use it? and when?

≯℡__Kan透↙ 提交于 2021-02-07 10:23:22
问题 Recently I got question about which one is the most fastest thing among iterator , list comprehension , iter(list comprehension) and generator . and then make simple code as below. n = 1000000 iter_a = iter(range(n)) list_comp_a = [i for i in range(n)] iter_list_comp_a = iter([i for i in range(n)]) gene_a = (i for i in range(n)) import time import numpy as np for xs in [iter_a, list_comp_a, iter_list_comp_a, gene_a]: start = time.time() np.sum(xs) end = time.time() print((end-start)*100) the

Can I memoize a Python generator?

时间秒杀一切 提交于 2021-02-05 20:01:12
问题 I have a function called runquery that makes calls to a database and then yields the rows, one by one. I wrote a memoize decorator (or more accurately, I just stole one from this stackoverflow question) but on subsequent calls it just yields an empty sequence, presumably because a generator's values can only be yielded once. How could I modify the memoization decorator that works for Python generators? I realise I will need to store it in memory at some point but I'd like to handle this

Can I memoize a Python generator?

浪子不回头ぞ 提交于 2021-02-05 19:58:22
问题 I have a function called runquery that makes calls to a database and then yields the rows, one by one. I wrote a memoize decorator (or more accurately, I just stole one from this stackoverflow question) but on subsequent calls it just yields an empty sequence, presumably because a generator's values can only be yielded once. How could I modify the memoization decorator that works for Python generators? I realise I will need to store it in memory at some point but I'd like to handle this

Nested generator expression - unexpected result [duplicate]

爷,独闯天下 提交于 2021-02-04 16:38:05
问题 This question already has answers here : Accessing class variables from a list comprehension in the class definition (5 answers) Why is one class variable not defined in list comprehension but another is? (1 answer) Closed 6 years ago . Here's the test code: units = [1, 2] tens = [10, 20] nums = (a + b for a in units for b in tens) units = [3, 4] tens = [30, 40] [x for x in nums] Under the assumption that the generator expression on line 3 ( nums = ... ) forms an iterator I would expect the

How to balance dataset using fit_generator() in Keras?

匆匆过客 提交于 2021-02-02 09:23:57
问题 I am trying to use keras to fit a CNN model to classify 2 classes of data . I have imbalanced dataset I want to balance the data. I don't know can I use class_weight in model.fit_generator . I wonder if I used class_weight="balanced" in model.fit_generator The main code : def generate_arrays_for_training(indexPat, paths, start=0, end=100): while True: from_=int(len(paths)/100*start) to_=int(len(paths)/100*end) for i in range(from_, int(to_)): f=paths[i] x = np.load(PathSpectogramFolder+f) x =