Iteratively prediction using caffe in a C++ project
<p>I am a beginner to caffe
. Recently I have been learning how to use a pretrained caffe model to do some  prediction in my own  project,
and now I am trying to do a iteratively prediction while in each loop there will be a new data(input) and will be used to predict something. </p>

<p>I use memory data layer as my data input layer. </p>

<p>Before entering the loop, I will make some declaration </p>

<pre><code>    caffe::Datum datum;
    datum.set_channels(1);
    datum.set_height(1);
    datum.set_width(30);
    vector&lt;float&gt; mydata;

    vector&lt;caffe::Datum&gt; dvector;
    boost::shared_ptr&lt;MemoryDataLayer&lt;float&gt; &gt; memory_data_layer;
    memory_data_layer = boost::static_pointer_cast&lt;MemoryDataLayer&lt;float&gt;&gt;(net.layer_by_name("datas"));
    const boost::shared_ptr&lt;Blob&lt;float&gt;&gt; &amp; blobs = net.blob_by_name("result");
    const float* output = blobs-&gt;cpu_data();
</code></pre>

<p>And in each loop, "mydata" will get some new data and will be used for a new prediction. </p>

<p>Here is what I do  in each loop</p>

<pre><code>    ("mydata" updated)

    datum.clear_data();

    for(int i=0;i&lt;30;i++)
    datum.add_float_data(mydata[i]);

    dvector.clear();
    dvector.push_back(datum);

    memory_data_layer-&gt;AddDatumVector(dvector);

    float loss = 0.0;
    net.Forward(&amp;loss);   
    for (int i = 0; i &lt; 10; i =++) 
       {               
              cout&lt;&lt; output[i] &lt;&lt;endl;
       }
</code></pre>

<p>For the first loop, the result is correct.
But for the following loop, though "mydata" get the new data, the output remains unchanged, it still show the same result as the first loop.</p>

<p>Did I skip any necessary step?
How to fix it?</p>

<p>Thanks.           </p>