The itertools "cycle" function is the least surprising method for that. Not sure exactly how you're trying to use it though.
-
-
-
The code I showed already works - I'm looking for a neater way to achieve the same thing. itertools.cycle() doesn't seem to do that afaict
-
Where does your code loop multiple times?
-
This IterPipe is wrapping a pytorch DataLoader. It does batchwise transformations to each batch. So each epoch, we do `for batch in data_loader` again (where 'data_loader' therefore is the IterPipe). Sorry I'm so bad at explaining this!
-
Do you have a list of transformations to apply to the batch? Synthetically creating more training data on a given epoch?
কথা-বার্তা শেষ
নতুন কথা-বার্তা -
-
-
Afaik all the lazy evaluation built-ins support lazy iterables as input, so no __len__ support without a custom class
-
Makes sense
কথা-বার্তা শেষ
নতুন কথা-বার্তা -
-
-
Actually, this is as concise as it gets. Slightly more idiomatically, if you are willing to trade the complexity of your wrapper for an extra function call, make data_loader() a function (or a closure) returning a fresh lazy iterable on the spot: 'for batch in data_loader(): ...'
-
Example: data_loader = lambda: map(func, iterator) # or: data_loader = functools.partial(map, func, iterator) for batch in data_loader(): ...
-
Drat. Now I see my data_loader does not provide a len() :)
-
Yup, but it's nearly there!
কথা-বার্তা শেষ
নতুন কথা-বার্তা -
-
-
import itertools class YourClass(object): def __init__(self,...): self.operations = [self.method1, self.method2,...] self.iterator = itertools.cycle(self.operations) def __call__(self,arguments): return next(self.iterator)(arguments)
ধন্যবাদ। আপনার সময়রেখাকে আরো ভালো করে তুলতে টুইটার এটিকে ব্যবহার করবে। পূর্বাবস্থায়পূর্বাবস্থায়
-
-
-
You could call list() on the iter if you're going to loop through whole of it multiple times
ধন্যবাদ। আপনার সময়রেখাকে আরো ভালো করে তুলতে টুইটার এটিকে ব্যবহার করবে। পূর্বাবস্থায়পূর্বাবস্থায়
-
-
-
If you know how many times you'll need to do the iteration by the time you instantiate IterPipe, itertools.tee might be what you're looking for.
ধন্যবাদ। আপনার সময়রেখাকে আরো ভালো করে তুলতে টুইটার এটিকে ব্যবহার করবে। পূর্বাবস্থায়পূর্বাবস্থায়
-
-
-
2/2 not necessarily the best option, it works for me on transforming data on the fly.
ধন্যবাদ। আপনার সময়রেখাকে আরো ভালো করে তুলতে টুইটার এটিকে ব্যবহার করবে। পূর্বাবস্থায়পূর্বাবস্থায়
-
লোড হতে বেশ কিছুক্ষণ সময় নিচ্ছে।
টুইটার তার ক্ষমতার বাইরে চলে গেছে বা কোনো সাময়িক সমস্যার সম্মুখীন হয়েছে আবার চেষ্টা করুন বা আরও তথ্যের জন্য টুইটারের স্থিতি দেখুন।