Tag Archives: TypeError: ‘builtin_function_or_method‘ object is unsubscriptable (

[Solved] PyTorch error: TypeError: ‘builtin_function_or_method‘ object is unsubscriptable

[this paper records two solutions for error reporting at the same time]

pytorch error: runtimeerror: Boolean value of tensor with more than one value is ambiguous

When writing Python code, if you want to view a dimension of a tenor, you use. Shape at the beginning

if test_image.shape[1] == 3:
    ......

Resulting error :

RuntimeError: Boolean value of Tensor with more than one value is ambiguous

This is because tensor can’t use .shape, but should use .size

So I wrote it as .size,

if test_image.size[1] == 3:
    ......

Resulting error reported.

TypeError: ‘builtin_function_or_method’ object is unsubscriptable

This is because the brackets [ ] are written incorrectly and should be used ():

if test_image.size(1) == 3:
  ......

Solve the problem