<p dir="auto">Illustration of root cause (mentioned in neighbour branch by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/robertlugg/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/robertlugg">@robertlugg</a>).<br>
Debug output is added to class methods:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class ProgbarLogger(Callback):
    &quot;&quot;&quot;Callback that prints metrics to stdout.

    # Arguments
        count_mode: One of &quot;steps&quot; or &quot;samples&quot;.
            Whether the progress bar should
            count samples seen or steps (batches) seen.
        stateful_metrics: Iterable of string names of metrics that
            should *not* be averaged over an epoch.
            Metrics in this list will be logged as-is.
            All others will be averaged over time (e.g. loss, etc).

    # Raises
        ValueError: In case of invalid `count_mode`.
    &quot;&quot;&quot;

    def __init__(self, count_mode='samples',
                 stateful_metrics=None):
        super(ProgbarLogger, self).__init__()
        if count_mode == 'samples':
            self.use_steps = False
        elif count_mode == 'steps':
            self.use_steps = True
        else:
            raise ValueError('Unknown `count_mode`: ' + str(count_mode))
        if stateful_metrics:
            self.stateful_metrics = set(stateful_metrics)
        else:
            self.stateful_metrics = set()

    def on_train_begin(self, logs=None):
        print('train begin')
        self.verbose = self.params['verbose']
        self.epochs = self.params['epochs']

    def on_epoch_begin(self, epoch, logs=None):
        print('epoch begin')
        if self.verbose:
            print('Epoch %d/%d' % (epoch + 1, self.epochs))
            if self.use_steps:
                target = self.params['steps']
            else:
                target = self.params['samples']
            print('Progbar initialization (target property is initially assigned here)')
            self.target = target
            self.progbar = Progbar(target=self.target,
                                   verbose=self.verbose,
                                   stateful_metrics=self.stateful_metrics)
        self.seen = 0

    def on_batch_begin(self, batch, logs=None):
        print('batch begin')
        if self.seen &lt; self.target:
            self.log_values = []

    def on_batch_end(self, batch, logs=None):
        print('batch end')
        logs = logs or {}
        batch_size = logs.get('size', 0)
        if self.use_steps:
            self.seen += 1
        else:
            self.seen += batch_size

        for k in self.params['metrics']:
            if k in logs:
                self.log_values.append((k, logs[k]))

        # Skip progbar update for the last batch;
        # will be handled by on_epoch_end.
        if self.verbose and self.seen &lt; self.target:
            self.progbar.update(self.seen, self.log_values)

    def on_epoch_end(self, epoch, logs=None):
        print('epoch end')
        logs = logs or {}
        for k in self.params['metrics']:
            if k in logs:
                self.log_values.append((k, logs[k]))
        if self.verbose:
            self.progbar.update(self.seen, self.log_values)"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">ProgbarLogger</span>(<span class="pl-v">Callback</span>):
    <span class="pl-s">"""Callback that prints metrics to stdout.</span>
<span class="pl-s"></span>
<span class="pl-s">    # Arguments</span>
<span class="pl-s">        count_mode: One of "steps" or "samples".</span>
<span class="pl-s">            Whether the progress bar should</span>
<span class="pl-s">            count samples seen or steps (batches) seen.</span>
<span class="pl-s">        stateful_metrics: Iterable of string names of metrics that</span>
<span class="pl-s">            should *not* be averaged over an epoch.</span>
<span class="pl-s">            Metrics in this list will be logged as-is.</span>
<span class="pl-s">            All others will be averaged over time (e.g. loss, etc).</span>
<span class="pl-s"></span>
<span class="pl-s">    # Raises</span>
<span class="pl-s">        ValueError: In case of invalid `count_mode`.</span>
<span class="pl-s">    """</span>

    <span class="pl-k">def</span> <span class="pl-en">__init__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">count_mode</span><span class="pl-c1">=</span><span class="pl-s">'samples'</span>,
                 <span class="pl-s1">stateful_metrics</span><span class="pl-c1">=</span><span class="pl-c1">None</span>):
        <span class="pl-en">super</span>(<span class="pl-v">ProgbarLogger</span>, <span class="pl-s1">self</span>).<span class="pl-en">__init__</span>()
        <span class="pl-k">if</span> <span class="pl-s1">count_mode</span> <span class="pl-c1">==</span> <span class="pl-s">'samples'</span>:
            <span class="pl-s1">self</span>.<span class="pl-s1">use_steps</span> <span class="pl-c1">=</span> <span class="pl-c1">False</span>
        <span class="pl-k">elif</span> <span class="pl-s1">count_mode</span> <span class="pl-c1">==</span> <span class="pl-s">'steps'</span>:
            <span class="pl-s1">self</span>.<span class="pl-s1">use_steps</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>
        <span class="pl-k">else</span>:
            <span class="pl-k">raise</span> <span class="pl-v">ValueError</span>(<span class="pl-s">'Unknown `count_mode`: '</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">count_mode</span>))
        <span class="pl-k">if</span> <span class="pl-s1">stateful_metrics</span>:
            <span class="pl-s1">self</span>.<span class="pl-s1">stateful_metrics</span> <span class="pl-c1">=</span> <span class="pl-en">set</span>(<span class="pl-s1">stateful_metrics</span>)
        <span class="pl-k">else</span>:
            <span class="pl-s1">self</span>.<span class="pl-s1">stateful_metrics</span> <span class="pl-c1">=</span> <span class="pl-en">set</span>()

    <span class="pl-k">def</span> <span class="pl-en">on_train_begin</span>(<span class="pl-s1">self</span>, <span class="pl-s1">logs</span><span class="pl-c1">=</span><span class="pl-c1">None</span>):
        <span class="pl-en">print</span>(<span class="pl-s">'train begin'</span>)
        <span class="pl-s1">self</span>.<span class="pl-s1">verbose</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">params</span>[<span class="pl-s">'verbose'</span>]
        <span class="pl-s1">self</span>.<span class="pl-s1">epochs</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">params</span>[<span class="pl-s">'epochs'</span>]

    <span class="pl-k">def</span> <span class="pl-en">on_epoch_begin</span>(<span class="pl-s1">self</span>, <span class="pl-s1">epoch</span>, <span class="pl-s1">logs</span><span class="pl-c1">=</span><span class="pl-c1">None</span>):
        <span class="pl-en">print</span>(<span class="pl-s">'epoch begin'</span>)
        <span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">verbose</span>:
            <span class="pl-en">print</span>(<span class="pl-s">'Epoch %d/%d'</span> <span class="pl-c1">%</span> (<span class="pl-s1">epoch</span> <span class="pl-c1">+</span> <span class="pl-c1">1</span>, <span class="pl-s1">self</span>.<span class="pl-s1">epochs</span>))
            <span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">use_steps</span>:
                <span class="pl-s1">target</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">params</span>[<span class="pl-s">'steps'</span>]
            <span class="pl-k">else</span>:
                <span class="pl-s1">target</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">params</span>[<span class="pl-s">'samples'</span>]
            <span class="pl-en">print</span>(<span class="pl-s">'Progbar initialization (target property is initially assigned here)'</span>)
            <span class="pl-s1">self</span>.<span class="pl-s1">target</span> <span class="pl-c1">=</span> <span class="pl-s1">target</span>
            <span class="pl-s1">self</span>.<span class="pl-s1">progbar</span> <span class="pl-c1">=</span> <span class="pl-v">Progbar</span>(<span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-s1">self</span>.<span class="pl-s1">target</span>,
                                   <span class="pl-s1">verbose</span><span class="pl-c1">=</span><span class="pl-s1">self</span>.<span class="pl-s1">verbose</span>,
                                   <span class="pl-s1">stateful_metrics</span><span class="pl-c1">=</span><span class="pl-s1">self</span>.<span class="pl-s1">stateful_metrics</span>)
        <span class="pl-s1">self</span>.<span class="pl-s1">seen</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span>

    <span class="pl-k">def</span> <span class="pl-en">on_batch_begin</span>(<span class="pl-s1">self</span>, <span class="pl-s1">batch</span>, <span class="pl-s1">logs</span><span class="pl-c1">=</span><span class="pl-c1">None</span>):
        <span class="pl-en">print</span>(<span class="pl-s">'batch begin'</span>)
        <span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">seen</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">self</span>.<span class="pl-s1">target</span>:
            <span class="pl-s1">self</span>.<span class="pl-s1">log_values</span> <span class="pl-c1">=</span> []

    <span class="pl-k">def</span> <span class="pl-en">on_batch_end</span>(<span class="pl-s1">self</span>, <span class="pl-s1">batch</span>, <span class="pl-s1">logs</span><span class="pl-c1">=</span><span class="pl-c1">None</span>):
        <span class="pl-en">print</span>(<span class="pl-s">'batch end'</span>)
        <span class="pl-s1">logs</span> <span class="pl-c1">=</span> <span class="pl-s1">logs</span> <span class="pl-c1">or</span> {}
        <span class="pl-s1">batch_size</span> <span class="pl-c1">=</span> <span class="pl-s1">logs</span>.<span class="pl-en">get</span>(<span class="pl-s">'size'</span>, <span class="pl-c1">0</span>)
        <span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">use_steps</span>:
            <span class="pl-s1">self</span>.<span class="pl-s1">seen</span> <span class="pl-c1">+=</span> <span class="pl-c1">1</span>
        <span class="pl-k">else</span>:
            <span class="pl-s1">self</span>.<span class="pl-s1">seen</span> <span class="pl-c1">+=</span> <span class="pl-s1">batch_size</span>

        <span class="pl-k">for</span> <span class="pl-s1">k</span> <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-s1">params</span>[<span class="pl-s">'metrics'</span>]:
            <span class="pl-k">if</span> <span class="pl-s1">k</span> <span class="pl-c1">in</span> <span class="pl-s1">logs</span>:
                <span class="pl-s1">self</span>.<span class="pl-s1">log_values</span>.<span class="pl-en">append</span>((<span class="pl-s1">k</span>, <span class="pl-s1">logs</span>[<span class="pl-s1">k</span>]))

        <span class="pl-c"># Skip progbar update for the last batch;</span>
        <span class="pl-c"># will be handled by on_epoch_end.</span>
        <span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">verbose</span> <span class="pl-c1">and</span> <span class="pl-s1">self</span>.<span class="pl-s1">seen</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">self</span>.<span class="pl-s1">target</span>:
            <span class="pl-s1">self</span>.<span class="pl-s1">progbar</span>.<span class="pl-en">update</span>(<span class="pl-s1">self</span>.<span class="pl-s1">seen</span>, <span class="pl-s1">self</span>.<span class="pl-s1">log_values</span>)

    <span class="pl-k">def</span> <span class="pl-en">on_epoch_end</span>(<span class="pl-s1">self</span>, <span class="pl-s1">epoch</span>, <span class="pl-s1">logs</span><span class="pl-c1">=</span><span class="pl-c1">None</span>):
        <span class="pl-en">print</span>(<span class="pl-s">'epoch end'</span>)
        <span class="pl-s1">logs</span> <span class="pl-c1">=</span> <span class="pl-s1">logs</span> <span class="pl-c1">or</span> {}
        <span class="pl-k">for</span> <span class="pl-s1">k</span> <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-s1">params</span>[<span class="pl-s">'metrics'</span>]:
            <span class="pl-k">if</span> <span class="pl-s1">k</span> <span class="pl-c1">in</span> <span class="pl-s1">logs</span>:
                <span class="pl-s1">self</span>.<span class="pl-s1">log_values</span>.<span class="pl-en">append</span>((<span class="pl-s1">k</span>, <span class="pl-s1">logs</span>[<span class="pl-s1">k</span>]))
        <span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">verbose</span>:
            <span class="pl-s1">self</span>.<span class="pl-s1">progbar</span>.<span class="pl-en">update</span>(<span class="pl-s1">self</span>.<span class="pl-s1">seen</span>, <span class="pl-s1">self</span>.<span class="pl-s1">log_values</span>)</pre></div>
<p dir="auto">Caller code example:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="model.fit(
    np.ndarray(shape=(13, 2,)),
    np.ndarray(shape=(13, 2,)),
    batch_size=batch_size,
    validation_data=(
        np.ndarray(shape=(13, 2)),
        np.ndarray(shape=(13, 2)),
    ),
    callbacks=[callbacks.ProgbarLogger(count_mode='samples')],
    epochs=13,
    verbose=0) # &lt;&lt;&lt;"><pre class="notranslate"><span class="pl-s1">model</span>.<span class="pl-en">fit</span>(
    <span class="pl-s1">np</span>.<span class="pl-en">ndarray</span>(<span class="pl-s1">shape</span><span class="pl-c1">=</span>(<span class="pl-c1">13</span>, <span class="pl-c1">2</span>,)),
    <span class="pl-s1">np</span>.<span class="pl-en">ndarray</span>(<span class="pl-s1">shape</span><span class="pl-c1">=</span>(<span class="pl-c1">13</span>, <span class="pl-c1">2</span>,)),
    <span class="pl-s1">batch_size</span><span class="pl-c1">=</span><span class="pl-s1">batch_size</span>,
    <span class="pl-s1">validation_data</span><span class="pl-c1">=</span>(
        <span class="pl-s1">np</span>.<span class="pl-en">ndarray</span>(<span class="pl-s1">shape</span><span class="pl-c1">=</span>(<span class="pl-c1">13</span>, <span class="pl-c1">2</span>)),
        <span class="pl-s1">np</span>.<span class="pl-en">ndarray</span>(<span class="pl-s1">shape</span><span class="pl-c1">=</span>(<span class="pl-c1">13</span>, <span class="pl-c1">2</span>)),
    ),
    <span class="pl-s1">callbacks</span><span class="pl-c1">=</span>[<span class="pl-s1">callbacks</span>.<span class="pl-v">ProgbarLogger</span>(<span class="pl-s1">count_mode</span><span class="pl-c1">=</span><span class="pl-s">'samples'</span>)],
    <span class="pl-s1">epochs</span><span class="pl-c1">=</span><span class="pl-c1">13</span>,
    <span class="pl-s1">verbose</span><span class="pl-c1">=</span><span class="pl-c1">0</span>) <span class="pl-c"># &lt;&lt;&lt;</span></pre></div>
<p dir="auto">Output for initialisation and training start scenario in silent mode</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="train begin
epoch begin
batch begin
Traceback (most recent call last):
  File &quot;train_cli.py&quot;, line 398, in &lt;module&gt;
    start_training()
  File &quot;train_cli.py&quot;, line 349, in start_training
    initial_epoch=initial_epoch,
  File &quot;train_cli.py&quot;, line 234, in fit_model_softmax
    history_viz_cb,
  File &quot;/Users/ilyakutukov/anaconda3/envs/jenv/lib/python3.6/site-packages/keras/engine/training.py&quot;, line 1039, in fit
    validation_steps=validation_steps)
  File &quot;/Users/ilyakutukov/anaconda3/envs/jenv/lib/python3.6/site-packages/keras/engine/training_arrays.py&quot;, line 195, in fit_loop
    callbacks.on_batch_begin(batch_index, batch_logs)
  File &quot;/Users/ilyakutukov/anaconda3/envs/jenv/lib/python3.6/site-packages/keras/callbacks.py&quot;, line 91, in on_batch_begin
    callback.on_batch_begin(batch, logs)
  File &quot;/Users/ilyakutukov/anaconda3/envs/jenv/lib/python3.6/site-packages/keras/callbacks.py&quot;, line 316, in on_batch_begin
    if self.seen &lt; self.target:
AttributeError: 'ProgbarLogger' object has no attribute 'target'"><pre class="notranslate">train begin
epoch begin
batch begin
Traceback (most recent call last):
  File <span class="pl-s"><span class="pl-pds">"</span>train_cli.py<span class="pl-pds">"</span></span>, line 398, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    <span class="pl-en">start_training</span>()
  File <span class="pl-s"><span class="pl-pds">"</span>train_cli.py<span class="pl-pds">"</span></span>, line 349, <span class="pl-k">in</span> start_training
    initial_epoch=initial_epoch,
  File <span class="pl-s"><span class="pl-pds">"</span>train_cli.py<span class="pl-pds">"</span></span>, line 234, <span class="pl-k">in</span> fit_model_softmax
    history_viz_cb,
  File <span class="pl-s"><span class="pl-pds">"</span>/Users/ilyakutukov/anaconda3/envs/jenv/lib/python3.6/site-packages/keras/engine/training.py<span class="pl-pds">"</span></span>, line 1039, <span class="pl-k">in</span> fit
    validation_steps=validation_steps)
  File <span class="pl-s"><span class="pl-pds">"</span>/Users/ilyakutukov/anaconda3/envs/jenv/lib/python3.6/site-packages/keras/engine/training_arrays.py<span class="pl-pds">"</span></span>, line 195, <span class="pl-k">in</span> fit_loop
    callbacks.on_batch_begin(batch_index, batch_logs)
  File <span class="pl-s"><span class="pl-pds">"</span>/Users/ilyakutukov/anaconda3/envs/jenv/lib/python3.6/site-packages/keras/callbacks.py<span class="pl-pds">"</span></span>, line 91, <span class="pl-k">in</span> on_batch_begin
    callback.on_batch_begin(batch, logs)
  File <span class="pl-s"><span class="pl-pds">"</span>/Users/ilyakutukov/anaconda3/envs/jenv/lib/python3.6/site-packages/keras/callbacks.py<span class="pl-pds">"</span></span>, line 316, <span class="pl-k">in</span> on_batch_begin
    <span class="pl-k">if</span> self.seen <span class="pl-k">&lt;</span> self.target:
AttributeError: <span class="pl-s"><span class="pl-pds">'</span>ProgbarLogger<span class="pl-pds">'</span></span> object has no attribute <span class="pl-s"><span class="pl-pds">'</span>target<span class="pl-pds">'</span></span></pre></div>
<p dir="auto">This bug is related to:</p>
<ul dir="auto">
<li>AttributeError: 'ProgbarLogger' object has no attribute 'log_values' <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="285415836" data-permission-text="Title is private" data-url="https://github.com/keras-team/keras/issues/8944" data-hovercard-type="issue" data-hovercard-url="/keras-team/keras/issues/8944/hovercard" href="https://github.com/keras-team/keras/issues/8944">#8944</a></li>
<li>AttributeError: 'ProgbarLogger' object has no attribute 'log_values' <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="174418941" data-permission-text="Title is private" data-url="https://github.com/keras-team/keras/issues/3657" data-hovercard-type="issue" data-hovercard-url="/keras-team/keras/issues/3657/hovercard" href="https://github.com/keras-team/keras/issues/3657">#3657</a> (duplicate)</li>
</ul>
<hr>
<p dir="auto">Please make sure that the boxes below are checked before you submit your issue. If your issue is an implementation question, please ask your question on <a href="http://stackoverflow.com/questions/tagged/keras" rel="nofollow">StackOverflow</a> or <a href="https://keras-slack-autojoin.herokuapp.com/" rel="nofollow">join the Keras Slack channel</a> and ask there instead of filing a GitHub issue.</p>
<p dir="auto">Thank you!</p>
<ul class="contains-task-list">
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Check that you are up-to-date with the master branch of Keras. You can update with:<br>
pip install git+git://github.com/keras-team/keras.git --upgrade --no-deps</p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found <a href="https://www.tensorflow.org/get_started/os_setup" rel="nofollow">here</a>.</p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with:<br>
pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps</p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short). (patch with test coverage is provided)</p>
</li>
</ul>
<p dir="auto"><strong>fit_generator</strong>.</p>
<p dir="auto">It does work in:<br>
Python 3.6.5<br>
Keras 2.1.6</p>
<p dir="auto">But doesn't in:<br>
Python 3.6.8<br>
Keras 2.2.4</p>
<p dir="auto">Unless related to version of other modules.</p>