Tag Archives: python bug

AttributeError: can‘t set attribute [How to Solve]

Traceback (most recent call last):
  File "D:/master/Multi-level-DCNet-master/3leveldcnet.py", line 342, in <module>
    routings=args.routings)
  File "D:/master/Multi-level-DCNet-master/3leveldcnet.py", line 60, in MultiLevelDCNet
    conv, nb_filter = densenet.DenseBlock(x, growth_rate=32, nb_layers=8, nb_filter=32)
  File "D:\master\Multi-level-DCNet-master\densenet.py", line 64, in DenseBlock
    cb = __conv_block(x, growth_rate, bottleneck, dropout_rate, weight_decay)
  File "D:\master\Multi-level-DCNet-master\densenet.py", line 27, in __conv_block
    x = BatchNormalization(axis=concat_axis, epsilon=1.1e-5)(ip)
  File "D:\Anaconda\envs\tensorflow\lib\site-packages\keras\engine\topology.py", line 575, in __call__
    self.build(input_shapes[0])
  File "D:\Anaconda\envs\tensorflow\lib\site-packages\keras\layers\normalization.py", line 103, in build
    constraint=self.gamma_constraint)
  File "D:\Anaconda\envs\tensorflow\lib\site-packages\keras\legacy\interfaces.py", line 87, in wrapper
    return func(*args, **kwargs)
  File "D:\Anaconda\envs\tensorflow\lib\site-packages\keras\engine\topology.py", line 399, in add_weight
    constraint=constraint)
  File "D:\Anaconda\envs\tensorflow\lib\site-packages\keras\backend\tensorflow_backend.py", line 323, in variable
    v.constraint = constraint
AttributeError: can't set attribute

Modify parts of the code:

v = tf.Variable(value, dtype=_convert_string_dtype(dtype), name=name)
    if isinstance(value, np.ndarray):
        v._keras_shape = value.shape
    elif hasattr(value, 'get_shape'):
        v._keras_shape = int_shape(value)
    v._uses_learning_phase = False
    # TODO: move to `tf.get_variable` when supported in public release.
    v.constraint = constraint  #Modify to v._constraint = constraint
    return v

AttributeError: ‘_io.TextIOWrapper‘ object has no attribute ‘softspace‘

Write the title of the table of contents here

1. Problem presentation 2. Solutions

1. Problem presentation

Problem display:

when I was learning the file module, I encountered such a situation. How can I solve this situation?

2. Solutions

This involves a version problem. As we all know, Python is mainly divided into Python 2 and python 3. When we check the python official website, we can see that
(Python website address: www.python. ORG)

it can be seen that in versions above 3.0, the softspace attribute may have been removed, so use the command line py – 2 (if you do not install python2, you need to install python2 first, python2 and python3 can be installed at the same time, and use py – 2 and py – 3 to switch under Windows Environment) to switch to python2.7, Open a file to view the softspace property, and the command line executes normally.

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host=‘localhost‘, port=8097): Max retries excee

After using visdom, the following problem occurs.

requests.exceptions.ConnectionError: HTTPConnectionPool(host=’localhost’, port=8097): Max retries exceeded with url: /env/main (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x0000027F8769B7F0>: Failed to establish a new connection: [WinError 10061] Unable to connect due to aggressive rejection by the target computer.’))
[WinError 10061] Unable to connect because the target computer is actively rejecting.
Visdom python client failed to establish socket to get messages from the server. This feature is optional and can be disabled by initializing Visdom with `use_incoming_socket=False`, which will prevent waiting for this request to timeout.
Setting up a new session…

visdom The above problem will also occur if it is not started.
Solution.

python -m visdom.server