Expected Tensor as element 0 in argument 0, but got list

ryunosuke0723: <p>I tried to convert tensor to list .<br>
But , the error occurred. What is the way to fix it?<br>
The value of list contains tensor([-0.2667,  0.1658,  0.0294,  …, -0.0293,  0.3530, -0.4136],<br>
grad_fn=),<br>
error message</p>
<pre><code class="lang-auto">emp = torch.stack([temp], dim=1)
expected Tensor as element 0 in argument 0, but got list
</code></pre>
<p>cord</p>
<pre><code class="lang-auto">
if __name__ == '__main__':

    myo.init(bin_path=r'C:\Users\name\Desktop\myo-sdk-win-0.9.0\bin')
    HUB = myo.Hub()
    model.eval()
    listener = MyListener()
    start = time.time()
    temp = []
    with HUB.run_in_background(listener.on_event):
        while True:
            data = listener.get_emg_data()
            if time.time() - start &gt;= 10:
                print(temp) # 656
                temp = torch.stack([temp], dim=1)
                response = torch.argmax(torch.bincount(temp)) # numpy形式
                #response = torch.tensor(response)
                print(response)
                print("Predicted gesture: {0}".format(response))
                temp = []
                start = time.time()

            if len(data) &gt; 0:              # len(data) = 8
                tmp = []
                for v in listener.get_emg_data():
                    tmp.append(v[1])
                tmp = list(np.stack(tmp).flatten())
                tmp = torch.tensor(tmp)  # tensor型に変換（listの中身を）
                #print(tmp)
                if len(tmp) &gt;= 64:
                    pred = model(tmp)
                    #pred = torch.mean(_,predicted, feed_dict={x: np.array([tmp])})
                    #pred = sess.run(y_pred_cls, feed_dict={x: np.array([tmp])})
                    #print(pred)
                    temp.append(pred[0])
            sleep(0.01)

</code></pre>

albanD: <p>Hi,</p>
<p>The first argument to <code>torch.stack</code> should be a list that contains Tensors.<br>
So you just want to make sure that your argument is that.</p>

HaithemH: <p>I have got the same error here:</p>
<p>def collate_batch(self, features: List[Union[InputDataClass, Dict]]) → Dict[str, torch.Tensor]:</p>
<pre><code>    first = features[0]

    if isinstance(first, dict):

      # NLP data sets current works presents features as lists of dictionary

      # (one per example), so we  will adapt the collate_batch logic for that

      if "labels" in first and first["labels"] is not None:

          if first["labels"].dtype == torch.int64:

              labels = torch.tensor([f["labels"] for f in features], dtype=torch.long)

          else:

              labels = torch.tensor([f["labels"] for f in features], dtype=torch.float)

          batch = {"labels": labels}

      for k, v in first.items():

          if k != "labels" and v is not None and not isinstance(v, str):

             print([f[k] for f in features][0])

              batch[k] = torch.stack([f[k] for f in features])

      return batch

 29                   print([f[k] for f in features][0])
</code></pre>
<p>—&gt; 30                   batch[k] = torch.stack([f[k] for f in features])<br>
31           return batch</p>
<p>TypeError: expected Tensor as element 0 in argument 0, but got list</p>

Waleed_Eid: <p>Hi , replace to torch.tensor insted of torch.stack</p>