question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

can we collate data and save to disk when overriding __inc__?

See original GitHub issue

❓ Questions & Help

Hi, thanks for the great library! I have a question. I am making customized data class just like the BipartiteData you mentioned here:https://pytorch-geometric.readthedocs.io/en/latest/notes/batching.html. However, I notice in the examples you didn’t call:

data, slices = self.collate(data_list)
torch.save((data, slices), self.processed_paths[0])

Since my dataset is large, I prefer to make it once and save it. However, I failed to run self.collate. My customized Data class is like this

class CorrData(Data):
    def __init__(self, vtx, pts, edge_vtx, edge_pts, corr, name):
        super(CorrData, self).__init__()
        self.vtx = vtx
        self.pts = pts
        self.edge_index_vtx = edge_vtx
        self.edge_index_pts = edge_pts
        self.corr = corr
        self.name = name

    def __inc__(self, key, value):
        if key == 'edge_index_vtx':
            return self.vtx.size(0)
        if key == 'edge_index_pts':
            return self.pts.size(0)
        if key == 'corr':
            return torch.tensor([[self.vtx.size(0)], [self.pts.size(0)]])
        else:
            return super(CorrData, self).__inc__(key, value)

    def __cat_dim__(self, key, value):
        if 'edge_index' in key:
            return 1
        else:
            return 0

The reported error is like this:

File “xxxx/datasets/corr_dataset.py”, line 141, in process data, slices = self.collate(data_list) File “xxxx/torch_geometric/data/in_memory_dataset.py”, line 93, in collate data = data_list[0].class() TypeError: init() missing 6 required positional arguments: ‘vtx’, ‘pts’, ‘edge_vtx’, ‘edge_pts’, ‘corr’, and ‘name’

Any suggestion about how to solve this? Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rusty1scommented, Aug 21, 2020

Regarding your first issue: This was a bug introduced in PyG 1.6.0, but it is fixed in PyG 1.6.1. Sorry! Regarding your warning: Do you know where exactly this warning does occur? This shouldn’t happen either.

1reaction
rusty1scommented, Aug 20, 2020

In general, collate should be usable even for custom Data objects. You can fix the error by changing:

def __init__(self, vtx, pts, edge_vtx, edge_pts, corr, name):

to

def __init__(self, vtx=None, pts=None, edge_vtx=None, edge_pts=None, corr=None, name=None):
Read more comments on GitHub >

github_iconTop Results From Across the Web

Method Overriding in Python
Example: Let's consider an example where we want to override a method of one parent class only. Below is the implementation.
Read more >
Save documents in InDesign
Saving a document saves the current layout, references to source files, which page is currently displayed, and the zoom level. Protect your work ......
Read more >
Method Overloading vs Method Overriding in Java
In this article, we will learn about method overloading and overriding in Java. Following are the topics discussed in this blog:.
Read more >
3 Ways to Recover Overwritten Excel File in Windows 11 ...
Data overwriting generally occurs in a computer when you have some lost files but keep storing new data on the computer. It can...
Read more >
Protect your enterprise data using Windows Information ...
Microsoft will continue to support WIP on supported versions of ... For your data protection needs, Microsoft recommends that you use ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found