Objectorientedprogramming in pytorch

i recently learned oops and i am wondering what is utils.data.dataloader is could anyone please tell me structure of code like what is class here and what is function here and what is module here


I am not sure to understand your question fully.
But in general in pytorch, we use capital letters for classes and lower case for regular functions. Does that answer your question?

firstofall i am sorry for wasting your precious time my doubt is i dont understand the working of pytorch. could you please tell me what happens when i type import torch (i belive a file called torch would be acessible to use in code). if my assumption is true then what does utils.data.dataloader does . i get the point that dataloader() is a function then what are utils and data representing are these representing classes or something like that. to be precise my question is regarding structure of the command torch.utils.data.dataloader() what are we accessing (could you please tell me like you are accessing module>>file>>class>>function) i am asking about the structure what is class here what is module here what is file here of course i can understand dataloader is function but what are data and utils. hope i made my doubt clear

is it that torch.tensor tensor function is present in init file
so that torch is module utils is file data is class and dataloader is class
in official docs there is no word about oops part


For torch.utils.data.DataLoader, torch, utils, data are modules. And DataLoader is a class define in the data module.
You might want to find a course on python to understand these things better.

ok i get it but non of the courses i learnt told me that you can call a class. i mean they taught me only functions can be called . can classes be called then what component in classes are we calling is it that we are passing arguments using brackets(ie class(argument1,argument2)) and we are useing these arguments to get values for processing i mean if we call a function it returns a value but if we call a class what does it return (a value?)

When you do dataloader = torch.utils.data.DataLoader(args). Then you create a new instance of the class DataLoader. This calls the __init__() function defined for that class.
Now if you call the instance dataloader(), then it will call the __call__() method on the class.

You can simply override that method to make your class instance callable.

@albanD sorry if i am disturbing you . i would like to ask you one question
1.if i import torch then if there is a file called tensor.py which contains the (assume) class tensor1 then if i need to call the class tensor1 is it enough to call tensor1() or should i call tensor.tensor1

When you import torch. It will look for the __init__.py file in the torch/ folder (local folder or in the install directories of python).

For calling things inside a python module, it will depend how you import it. But here again you will get a much better idea by reading about python modules directly to get a better sense of what is happening.

@albanD ok as of now does is thinking pytorch omits file and only takes only directories and classes makes sense right? . can i imagine like if you use import then classes in all files (.py files) present in that directory gets copied to init


I’m sorry I don’t understand your question :confused:
Note that pytorch is doing nothing special here. It just uses python constructs and is built like any other python package.

@albanD i got it a user called chetan answered me however thanks a lot for the help and time
my question was actually that python ignores file in path ie if a class is inside
pkg1-subpkg1-file.py-class then to acess it pkg1.subpkg1.class() it omits file

could you please answer this question