Tag Archives: python

AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘H:\\yolov5-5.0\\models\\

import warnings
class SPPF(nn.Module):
    # Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher
    def __init__(self, c1, c2, k=5):  # equivalent to SPP(k=(5, 9, 13))
        super().__init__()
        c_ = c1 // 2  # hidden channels
        self.cv1 = Conv(c1, c_, 1, 1)
        self.cv2 = Conv(c_ * 4, c2, 1, 1)
        self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)
 
    def forward(self, x):
        x = self.cv1(x)
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')  # suppress torch 1.9.0 max_pool2d() warning
            y1 = self.m(x)
            y2 = self.m(y1)
            return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))

Modified in moudle commom.py

[Solved] Tensorflow Error: failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED

Tensorflow failed to create cublas handle: cublas_ STATUS_ ALLOC_ FAILED

Foreword problem description problem solving reference link

preface

After many days of in-depth learning, I finally learned to use GPU. I was very happy, but I chatted with my classmates and learned that my 1660ti running in-depth learning is nothing. Dunton doesn’t hold any hope. It’s good to use notebooks for learning. If you really run in-depth learning, you have to use laboratory computers. Alas, there’s still no money

Problem description

An error occurred while using GPU

2021-11-09 20:43:26.114720: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_100.dll
2021-11-09 20:43:26.386261: E tensorflow/stream_executor/cuda/cuda_blas.cc:238] failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED
2021-11-09 20:43:26.386617: E tensorflow/stream_executor/cuda/cuda_blas.cc:238] failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED
2021-11-09 20:43:26.386735: W tensorflow/stream_executor/stream.cc:1919] attempting to perform BLAS operation using StreamExecutor without BLAS support
Traceback (most recent call last):
  File "first.py", line 30, in <module>
    gpu_time = timeit.timeit(gpu_run,number=10)
  File "D:\Anaconda\Anaconda3\envs\tensorflow2_0_0_gpu\lib\timeit.py", line 233, in timeit
    return Timer(stmt, setup, timer, globals).timeit(number)
  File "D:\Anaconda\Anaconda3\envs\tensorflow2_0_0_gpu\lib\timeit.py", line 177, in timeit
    timing = self.inner(it, self.timer)
  File "<timeit-src>", line 6, in inner
  File "first.py", line 21, in gpu_run
    c = tf.matmul(gpu_a,gpu_b)
  File "D:\Anaconda\Anaconda3\envs\tensorflow2_0_0_gpu\lib\site-packages\tensorflow_core\python\util\dispatch.py", line 180, in wrapper
    return target(*args, **kwargs)
  File "D:\Anaconda\Anaconda3\envs\tensorflow2_0_0_gpu\lib\site-packages\tensorflow_core\python\ops\math_ops.py", line 2765, in matmul
    a, b, transpose_a=transpose_a, transpose_b=transpose_b, name=name)
  File "D:\Anaconda\Anaconda3\envs\tensorflow2_0_0_gpu\lib\site-packages\tensorflow_core\python\ops\gen_math_ops.py", line 6126, in mat_mul
    _six.raise_from(_core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InternalError: Blas GEMM launch failed : a.shape=(10000, 1000), b.shape=(1000, 2000), m=10000, n=2000, k=1000 [Op:MatMul] name: MatMul/

I was in a hurry to find out the reason. I didn’t have enough video memory, and the GPU didn’t run full

Solution:

There are two main reasons
1. The versions of cudnn and CUDA and tensorflow are not applicable, but mine are based on the tutorial and confirmed several times to ensure that they are OK. This excludes the shortage of GPU video memory. It can be solved through the method on the official website: t because ensorflow 2.0 supports two GPU computing methods:
(1) dynamically allocate video memory
(2) set hard video memory (for example, only 1g video memory can be used, and others can play games
set the mode to (1) dynamic allocation, and the code is;

import tensorflow as tf

gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
tf.config.experimental.set_memory_growth(gpus[0], True)

VScode import numpy Error: DLL load failed [How to Solve]

vscode & Anaconda import numpy failed: DLL load failed

Phenomenon:
in Anaconda prompt, import numpy is normal
in vscode, import numpy reports an error: DLL load failed

Error reason:
shell opening failed, resulting in CONDA activate failure. There is no environment, and naturally there is no numpy

Solution:
open the vscodesettings.json file

(type)               CTRL + SHIFT + P
(search for:)        open settings
(click:)             Preferences: Open Settings (JSON)

Add in settings.json:

	"terminal.integrated.profiles.windows":{
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "Git Bash": {
            "source": "Git Bash"
        }
    },
    "terminal.integrated.defaultProfile.windows":"Command Prompt" 

In addition, I also refer to another blog. You need to configure the environment variable
and put the following contents into this computer -> Attribute -> Advanced system settings -> Environment variable -> Path path:

D:\anaconda
D:\anaconda\Scripts
D:\anaconda\Library\bin
D:\anaconda\Library\user\bin
D:\anaconda\Library\mingw-w64\bin

[Solved] Failed to obtain/convert traceback after Python Tkinter packages exe

Exe in Python Tkinter packaging causes failed to obtain/convert traceback!

Problem description

python 3.9
windows 10
Packaged and executed commands
pyinstaller -D -w -i xx.ico main.py

After using pyinstaller to package exe, click the EXE file and an error occurs
failed to obtain/convert traceback
the details are shown in the figure:

Cause of problem

After troubleshooting, it is found that there is no problem with the packaged commands. The problem is that the database does not import data during initialization. The data is null. Just fill in the corresponding database values
summary: the problem is that the code does not handle exceptions properly.

solve the problem

    handle the corresponding code exceptions (including those where exceptions may occur) and populate the database

[Solved] TensorFlow Error: GetNext() failed because the iterator has not been initialized

Error Messages:
FailedPreconditionError (see above for traceback): GetNext() failed because the iterator has not been initialized. Ensure that you have run the initializer operation for this iterator before getting the next element. [[Node: IteratorGetNext = IteratorGetNextoutput_shapes=[, ], output_types=[DT_UINT8, DT_UINT8], _device=”/job:localhost/replica:0/task:0/device:CPU:0″]]

Solution:
Iterator is not initialized
Add before the error code: sess.run(iterator.initializer)

refer to: https://stackoverflow.com/questions/48443203/tensorflow-getnext-failed-because-the-iterator-has-not-been-initialized

tensorflow.python.framework.errors_impl.InternalError: Blas xGEMM launch failed

When running the image stylization code with tensorflow version 2.4.0, the following error occurred:

tensorflow.python.framework.errors_impl.InternalError: Blas xGEMM launch failed : a.shape=[1,480000,64], b.shape=[1,480000,64], m=64, n=64, k=480000 [Op:Einsum]

The following two solutions are found by consulting the data:
1. Add the following code to the program:

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '/gpu:0'

The program can run normally, but the CPU is used, and the running speed of the program is much slower
2. Modify the cudnn version, but it is generally not recommended. It is too troublesome.

How to solve the [error 11004] getaddrinfo failed error in nltk downloader

Recently, I used nltk as a downloader in my homework related to automatic Q & A. I used another computer to solve the problem, but I didn’t record the solution. I immediately forgot and spent about 2 hours looking for a solution. Therefore, I want to record the solution now.

import nltk

nltk.download('stopwords')
nltk.download('reuters')
nltk.download('punkt')

When executing the above code, an error is found error loading stopwords: & lt; Urlopen error [errno 11004] getaddrinfo failed , the following methods are available through practical operation.

Find the hosts file under C: \ windows \ system32 \ drivers \ etc , open it as an administrator, and add the following line of IP address to the end of hosts.

185.199.108.133 raw.githubusercontent.com

As shown in the figure below,
after adding and running again, you will find that the download is successful

The address of raw.github is changed frequently, resulting in unsuccessful download

It is possible that the address may be changed frequently, resulting in unsuccessful downloading. We can open the website for querying the IP address: https://www.ipaddress.com/ Enter raw. Githubusercontent. Com to find the corresponding new IP address.

give an example

We have added the IP address to the hosts and found that it was still unsuccessful. Therefore, let’s see if the download failed due to the change of the IP address of raw.github. We open https://websites.ipaddress.com/ website, enter raw.githubusercontent.com , and click look up
. It is found that four IPS have been found. We replace the content in hosts with

185.199.109.133 raw.githubusercontent.com

Then we re execute and find success.

If the above solutions are not solved, you can leave a message and we can communicate together~

The above solutions are from the solution reference link. Thank you very much!!

[Solved] Odoo Cannot log in error after the Database is Recovered

Many odoo users have encountered the problem that the backed up database cannot be restored

You can self-check in the following ways

1. Is the odoo version correct? Different versions of odoo cannot be restored directly, for example, odoo13 cannot be restored directly to odoo15

2. Whether the database version is correct, postgres may have problems when it is backward compatible. It is recommended to migrate to the same version.

3. Whether the code is migrated correctly, inconsistent codes on both sides will also cause an error, which is common in the conf file without specifying the code location.

If you confirm that the above content is correct, you can try the following methods

1. Add -d database name -i base when starting odoo through the command line, this method is to select the database to force the update of the base module; because all odoo modules are dependent on this, the mandatory update will be all the modules installed in the database after the base Will be upgraded.

2. Enter postgres, enter the following command

su postgres; # Switch postgres users
psql; # Enter the postgres command line
\c; database name # specify database instance
DELETE FROM ir_attachment WHERE url LIKE '/web/content/%'; # Delete the front-end files cached in the data table

Generally, most problems can be solved through the above two steps.

An error occurs when pymysql uses% d to pass in parameters

Error:

When using pymysql, an error occurs when using% d to pass parameters in the SQL statement. As shown in the figure:

Error information: typeerror:% d format: a number is required, not str

Cause of problem:

         When a parameter of type int is passed in, it is converted to a parameter of type str. Therefore, the solution is to change% d into% s, pass in int type, and it can still be executed.

Modified:

Data of type int passed in:

Can execute successfully

Solution:

          When data of type int is passed in, the parameter is still passed with% s.