TypeError: 'int' object is not callable

ky_Pa: <p>When I use the H5py library to read the .mat dataset, I get the following error. What is wrong? I have not found duplicate function and variable names. Thank you!</p>
<pre><code class="lang-auto">    tgt_dataset_root = h5py.File('E:\\ADDA\\pytorch-adda-master-lab\\datasets\\lab\\sandy\\mat\\test_target_domain_sandy.mat','r')
    data = tgt_dataset_root['data'] # use the key for data here
    label = tgt_dataset_root['label'] # use the key for target here

    data = numpy.array(data)
    label = numpy.array(label)

    tgt_dataset = TensorDataset(data, label)![微信图片_20200304093151|690x169](upload://nFSRllMj081KMNDu5qNcH1b2IaB.png)</code></pre>

ky_Pa: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/a/5/a5ee13bad47e7c75870106179829e30e33ef3f81.png" data-download-href="https://discuss.pytorch.org/uploads/default/a5ee13bad47e7c75870106179829e30e33ef3f81" title="微信图片_20200304093151"><img src="https://discuss.pytorch.org/uploads/default/original/3X/a/5/a5ee13bad47e7c75870106179829e30e33ef3f81.png" alt="微信图片_20200304093151" data-base62-sha1="nFSRllMj081KMNDu5qNcH1b2IaB" width="690" height="169" data-dominant-color="383933"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">微信图片_20200304093151</span><span class="informations">1041×255 14.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>Could you try to pass the <code>data</code> and <code>label</code> as tensors using <code>data = torch.from_numpy(data)</code>?</p>

ky_Pa: <p>Is that so? But the following error also occurs.How do I modify it?<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/7/279143c17218713aff0c1b2bc599e2c09f10a75e.png" data-download-href="https://discuss.pytorch.org/uploads/default/279143c17218713aff0c1b2bc599e2c09f10a75e" title="微信图片_20200304094127"><img src="https://discuss.pytorch.org/uploads/default/original/3X/2/7/279143c17218713aff0c1b2bc599e2c09f10a75e.png" alt="微信图片_20200304094127" data-base62-sha1="5E1QFmaHaojL9rIBfukZuDCZFO6" width="690" height="158" data-dominant-color="3B3C36"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">微信图片_20200304094127</span><span class="informations">743×171 7.37 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<pre><code class="lang-auto">    tgt_dataset_root = h5py.File('E:\\ADDA\\pytorch-adda-master-lab\\datasets\\lab\\sandy\\mat\\test_target_domain_sandy.mat','r')
    data = tgt_dataset_root['data'] # use the key for data here
    label = tgt_dataset_root['label'] # use the key for target here

    data = torch.from_numpy(data)
    label = torch.from_numpy(label)

    tgt_dataset = TensorDataset(data, label)</code></pre>

ptrblck: <p>I’m not sure how your data is stored, as the first error message points to an integer scalar value, while it now seems to be a <code>Dataset</code> class?<br>
Could you <code>print(type(data))</code> after indexing it from <code>tgt_dataset_root</code>?</p>

ky_Pa: <p>Look at it like this, how do I do next?<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/5/7/579ec137ae1e85f0ed5b4da3fc527de94ed728ff.png" alt="微信图片_20200304095529" data-base62-sha1="cv7Fz70DVE75LK6fkPJh9a9e4KH" width="406" height="110"></p>
<pre data-code-wrap="import"><code class="lang-import">
dict_data = h5py.File('E:\\ADDA\\pytorch-adda-master-lab\\datasets\\lab\\sandy\\mat\\test_target_domain_sandy.mat','r')

print (type(dict_data))
print(dict_data.keys())

data = dict_data['data']
print(type(data))</code></pre>

ptrblck: <p>You could try to call <code>data = dict_data['data'].value</code> to get the underlying numpy array, but I’m not too familiar with h5py.</p>

ky_Pa: <p>I got this result after trying. If the data is stored in the Dataset class as you said, how can I operate to load it?<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/2/2265bc0e340f2e4b6ab6ba77357585961aef0ad5.png" data-download-href="https://discuss.pytorch.org/uploads/default/2265bc0e340f2e4b6ab6ba77357585961aef0ad5" title="微信图片_20200304141715"><img src="https://discuss.pytorch.org/uploads/default/original/3X/2/2/2265bc0e340f2e4b6ab6ba77357585961aef0ad5.png" alt="微信图片_20200304141715" data-base62-sha1="4UicmjlSYOhPEiAjDB2MTXAAq3P" width="690" height="163" data-dominant-color="373832"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">微信图片_20200304141715</span><span class="informations">1307×310 19.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<pre><code class="lang-auto">    tgt_dataset_root = h5py.File('E:\\ADDA\\pytorch-adda-master-lab\\datasets\\lab\\sandy\\mat\\test_target_domain_sandy.mat','r')
    data = tgt_dataset_root['data'].value
    label = tgt_dataset_root['label'].value

    data = torch.from_numpy(data)
    label = torch.from_numpy(label)

    tgt_dataset = TensorDataset(data, label)</code></pre>

ptrblck: <p>Creating the tensors seems to work, while you are now facing an error stating the data and labels have a different length.<br>
I would recommend to check the correspondence between both tensors, as apparently you have either missing labels or missing data.</p>

ky_Pa: <p>Can you help me write down the specific code? I’m a bit confused now. Thank you very much!</p>

ptrblck: <p>One approach would be to get both lengths and cut the longer tensor to the size of the shorter one:</p>
<pre><code class="lang-python">min_len = min(data.size(0), target.size(0))
data = data[:min_len]
target = target[:min_len]
</code></pre>
<p>However, I would not recommend to just apply this approach, as you are apparently missing some data, so the correspondence between your data and target might be broken.</p>

ky_Pa: <p>I encountered such a problem, please take a look.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/8/4867e62834c4961926d95aba3eb80fbbdbe5edaf.png" data-download-href="https://discuss.pytorch.org/uploads/default/4867e62834c4961926d95aba3eb80fbbdbe5edaf" title="微信图片_20200304150821"><img src="https://discuss.pytorch.org/uploads/default/original/3X/4/8/4867e62834c4961926d95aba3eb80fbbdbe5edaf.png" alt="微信图片_20200304150821" data-base62-sha1="akwYNhunfUurfW6XtIsgW6iI1Sn" width="690" height="163" data-dominant-color="3E3F39"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">微信图片_20200304150821</span><span class="informations">729×173 7.59 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>If you are calling <code>size</code> on the numpy arrays, use <code>.shape[0]</code> instead.<br>
The provided code should work on the created tensors.</p>

ky_Pa: <p>Can you provide specific code, I am not very clear about these conversions. Thank you!</p>

ptrblck: <pre><code class="lang-python">tgt_dataset_root = h5py.File('E:\\ADDA\\pytorch-adda-master-lab\\datasets\\lab\\sandy\\mat\\test_target_domain_sandy.mat','r')
data = tgt_dataset_root['data'].value
label = tgt_dataset_root['label'].value

min_len = min(data.shape[0], label.shape[0])
data = data[:min_len]
label = label[:min_len]

data = torch.from_numpy(data)
label = torch.from_numpy(label)
</code></pre>
<p>should work.</p>

ky_Pa: <p>Thank you very much for your patience and guidance. Now both data and label can be printed separately. If it is used as a data set, do we still need to integrate it like this?</p>
<pre><code class="lang-auto">tgt_dataset = TensorDataset(data, label)</code></pre>

ptrblck: <p>Yes, you still should pass it to a <code>TensorDataset</code>.</p>

ky_Pa: <p>How can I fix this warning?<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/0/40026887d1e49210dee3f93bb9d5df23c0ce98b7.png" data-download-href="https://discuss.pytorch.org/uploads/default/40026887d1e49210dee3f93bb9d5df23c0ce98b7" title="微信图片_20200305112519"><img src="https://discuss.pytorch.org/uploads/default/original/3X/4/0/40026887d1e49210dee3f93bb9d5df23c0ce98b7.png" alt="微信图片_20200305112519" data-base62-sha1="98fIvFqRKwzCs1KowRUg8WVJJJR" width="690" height="49" data-dominant-color="3A3B35"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">微信图片_20200305112519</span><span class="informations">1262×91 7.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>