AnswerDotAI / AnswerDotAI/fastprogress

Is there a way to deal with variable sized iterables?

Aperta
#64 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Jupyter Notebook
Stelle
1.1k
Fork
104
Merge medio
1m
PR unite (30g)
1

Descrizione

The problem is this line:
`self.total = len(gen) if total is None else total`

That is executed at the beginning. But `len(gen)` might change throughout the iteration, but progress_bar just assumes it keeps still.

What I really want is to use a timer (so "train for 1 hour" instead of "train for so and so epochs").

```python
import time
class Timer:
def __init__(self, num_seconds):
self.num_seconds = num_seconds
self.i = None

def __len__(self):
if self.i is None: return 1
eps = 1e-7
t = time.time() - self.start
progress = t/num_seconds
return int((num_seconds*self.i)/(progress+eps)) # estimated size. Changes constantly.

def __iter__(self):
self.start = time.time()
self.i, t = 0, 0.0
while t <= self.num_seconds:
t = time.time() - self.start
self.i += 1
yield None
```

With this class, if you write
```python
for t in Timer(3.0):
# do stuff
```
it runs for 3 seconds. But it doesn't work with the `progress_bar` :(

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia individuando l’implementazione di progress_bar e la riga `self.total = len(gen) if total is None else total` descritta nell’issue. Riproduci l’esempio di Timer fornito, quindi determina come rappresentare gli iterable di dimensioni variabili o l’iterazione basata sul tempo; il lavoro è completo quando la barra di avanzamento può gestire questo caso d’uso senza presumere una lunghezza fissa.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
40/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.