_message.Message._CheckCalledFromGeneratedFile() TypeError: Descriptors cannot not be created directly.
时间: 2024-05-18 22:18:27 浏览: 260
_message.Message._CheckCalledFromGeneratedFile() TypeError: Descriptors should not be created directly, but only retrieved from their parent.这个错误通常是在使用caffe模型转tensorflow模型代码时出现的。解决方法是将caffe_pb.py的文件名改为caffe_pb2.py,并删除caffe_pb.pyc文件。然后重新调用convert.py即可解决该问题。<span class="em">1</span><span class="em">2</span>
相关问题
报错:TypeError: Descriptors cannot not be created directly.
这个错误通常是由于在创建描述符时使用了错误的语法或方法而导致的。描述符是一种特殊的对象,用于控制对类属性的访问和操作。以下是可能导致此错误的一些原因:
1. 没有正确实现描述符协议,即__get__,__set__和__delete__方法中的一种或多种方法没有正确实现。
2. 在创建描述符时使用了错误的语法或方法,例如在类或对象级别上使用了@property或@staticmethod修饰符。
3. 描述符对象没有正确初始化或参数传递错误。
要解决此问题,请检查代码并确保正确实现描述符协议,并正确使用描述符对象的语法和方法。如果仍然存在问题,请提供更多的上下文和代码示例以帮助确定问题。
TypeError: Descriptors cannot not be created directly.
This error occurs when you try to create descriptors directly instead of using them as part of a class definition. Descriptors are special objects that are used to define attributes of a class, and they need to be defined within the class definition.
For example, if you want to define a descriptor for a specific attribute of a class, you would define it like this:
```
class MyDescriptor:
def __get__(self, instance, owner):
# code to get the attribute value
pass
def __set__(self, instance, value):
# code to set the attribute value
pass
class MyClass:
my_attr = MyDescriptor()
```
In this example, `MyDescriptor` is defined within the class definition of `MyClass`, and `my_attr` is an attribute of `MyClass` that is defined using `MyDescriptor`.
If you try to create `MyDescriptor` outside of the class definition, you will get the "TypeError: Descriptors cannot not be created directly" error:
```
my_descriptor = MyDescriptor() # TypeError: Descriptors cannot not be created directly
```
阅读全文