Skip to main content
Post Undeleted by Markus
deleted 97 characters in body
Source Link
Markus
  • 111
  • 5

model.parameters()

It's simply because it returns an iterator object, not a list or something like that. But it behaves quite similar to a list. You can iterate over it eg with

[x for x in model.parameters()]

Or you can convert it to a list

[list(model.parameters())]

Iterators have some advantages over lists. Eg they are not "calculated" when they are created, which can improve performance.

For more on iterators just google for "python iterators", you'll find plenty of information. Eg w3schools.com is a good source.

model.parameters

The output model.parameters consists of two parts.

The first part bound method Module.parameters of tells you that you are referencing the method Module.parameters.

The second part tells you more about the object containing the referenced method. It' s the "object description" of your model variable. It's the same as print(model)

more on python references

model.parameter is just a reference to the parameter function, it's not executing the function. model.parameter() instead is executing it.

Maybe it gets more clear with a simple example.

print("Hello world") >>> Hello world print >>> <function print> abc = print abc("Hello world") >>> Hello world abc >>> <function print> 

As you see abc behave exactly the same as print because i assigned the reference of print to abc.

If I would have executed the function instead, eg abc = print("Hello world"), abc would contain the string Hello world and not the function reference to print.

It's simply because it returns an iterator object, not a list or something like that. But it behaves quite similar to a list. You can iterate over it eg with

[x for x in model.parameters()]

Or you can convert it to a list

[list(model.parameters())]

Iterators have some advantages over lists. Eg they are not "calculated" when they are created, which can improve performance.

For more on iterators just google for "python iterators", you'll find plenty of information. Eg w3schools.com is a good source.

model.parameters()

It's simply because it returns an iterator object, not a list or something like that. But it behaves quite similar to a list. You can iterate over it eg with

[x for x in model.parameters()]

Or you can convert it to a list

[list(model.parameters())]

Iterators have some advantages over lists. Eg they are not "calculated" when they are created, which can improve performance.

For more on iterators just google for "python iterators", you'll find plenty of information. Eg w3schools.com is a good source.

model.parameters

The output model.parameters consists of two parts.

The first part bound method Module.parameters of tells you that you are referencing the method Module.parameters.

The second part tells you more about the object containing the referenced method. It' s the "object description" of your model variable. It's the same as print(model)

more on python references

model.parameter is just a reference to the parameter function, it's not executing the function. model.parameter() instead is executing it.

Maybe it gets more clear with a simple example.

print("Hello world") >>> Hello world print >>> <function print> abc = print abc("Hello world") >>> Hello world abc >>> <function print> 

As you see abc behave exactly the same as print because i assigned the reference of print to abc.

If I would have executed the function instead, eg abc = print("Hello world"), abc would contain the string Hello world and not the function reference to print.

deleted 97 characters in body
Source Link
Markus
  • 111
  • 5

It's not pytorch specificsimply because it returns an iterator object, it's about python language syntaxnot a list or something like that. But it behaves quite similar to a list. You can iterate over it eg with

model.parameter is just a reference to the parameter function, it's not executing the function. [x for x in model.parameterparameters()] instead is executing it.

MaybeOr you can convert it gets more clear withto a simple example.list

print("Hello world") >>> Hello world print >>> <function print> abc = print abc("Hello world") >>> Hello world abc >>> <function print> 

As you see abc behave exactly the same as print because i assigned the reference of print to abc[list(model.parameters())].

If I wouldIterators have executed the function insteadsome advantages over lists. Eg they are not "calculated" when they are created, eg abc = print("Hello world")which can improve performance.

For more on iterators just google for "python iterators", abc would contain the stringyou'll find plenty of information. Eg Hello world and not the function reference to printw3schools.com is a good source.

It's not pytorch specific, it's about python language syntax.

model.parameter is just a reference to the parameter function, it's not executing the function. model.parameter() instead is executing it.

Maybe it gets more clear with a simple example.

print("Hello world") >>> Hello world print >>> <function print> abc = print abc("Hello world") >>> Hello world abc >>> <function print> 

As you see abc behave exactly the same as print because i assigned the reference of print to abc.

If I would have executed the function instead, eg abc = print("Hello world"), abc would contain the string Hello world and not the function reference to print.

It's simply because it returns an iterator object, not a list or something like that. But it behaves quite similar to a list. You can iterate over it eg with

[x for x in model.parameters()]

Or you can convert it to a list

[list(model.parameters())]

Iterators have some advantages over lists. Eg they are not "calculated" when they are created, which can improve performance.

For more on iterators just google for "python iterators", you'll find plenty of information. Eg w3schools.com is a good source.

Post Deleted by Markus
Source Link
Markus
  • 111
  • 5

It's not pytorch specific, it's about python language syntax.

model.parameter is just a reference to the parameter function, it's not executing the function. model.parameter() instead is executing it.

Maybe it gets more clear with a simple example.

print("Hello world") >>> Hello world print >>> <function print> abc = print abc("Hello world") >>> Hello world abc >>> <function print> 

As you see abc behave exactly the same as print because i assigned the reference of print to abc.

If I would have executed the function instead, eg abc = print("Hello world"), abc would contain the string Hello world and not the function reference to print.