Tag Archives: python

[Solved] AttributeError: ‘_IncompatibleKeys‘ object has no attribute ‘parameters‘

Errors are reported when running the pytorch program. It should be a problem with the torch syntax.

Original code:

model=CNN()#CNN as a self-compiling neural network model
best_model_wts = copy.deepcopy(model.state_dict())
*************************************#(the error codes is below)
model=model.load_state_dict(best_model_wts)

Error message:

Modified code:

model=CNN()#CNN as a self-compiling neural network model
best_model_wts = copy.deepcopy(model.state_dict())
model.load_state_dict(best_model_wts)

[Solved] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

INSERT INTO report(NAME,keyword,refile,content,DATE,STATUS) VALUES ('%s','%s','%s','%s','%s',0)%("name", "key", "refile", "content",str(datetime.now()))

report errors

ERROR CODE: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key,refile,content,date,status) VALUES ('%s','%s','%s','%s','%s',0)%("name", "ke' at line 1

The keyword of MySQL is used. After modification

    sql="INSERT INTO report(`name`,`keyword`,`refile`,`content`,`date`,`status`) VALUES ('%s','%s','%s','%s','%s',0)"%(name,key, refile, content,str(datetime.now()))

[Solved] python Connect hive to Install sasl Error: Building wheel for sasl (setup.py) … error

Collecting sasl
  Using cached sasl-0.3.1.tar.gz (44 kB)
Requirement already satisfied: six in c:\programdata\anaconda3\lib\site-packages (from sasl) (1.16.0)
Building wheels for collected packages: sasl
  Building wheel for sasl (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\ProgramData\Anaconda3\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'D:\\users\\jingtao.CENTALINE\\AppData\\Local\\Temp\\pip-install-2scxm6jd\\sasl_bdd59789a4b54e288cc48a38704a6ad4\\setu
p.py'"'"'; __file__='"'"'D:\\users\\jingtao.CENTALINE\\AppData\\Local\\Temp\\pip-install-2scxm6jd\\sasl_bdd59789a4b54e288cc48a38704a6ad4\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) e
lse io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'D:\users\jingtao.CENTALINE\AppData\Local\Te
mp\pip-wheel-ea8xc0cu'
       cwd: D:\users\jingtao.CENTALINE\AppData\Local\Temp\pip-install-2scxm6jd\sasl_bdd59789a4b54e288cc48a38704a6ad4\
  Complete output (28 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.9
  creating build\lib.win-amd64-3.9\sasl
  copying sasl\__init__.py -> build\lib.win-amd64-3.9\sasl
  running egg_info
  writing sasl.egg-info\PKG-INFO
  writing dependency_links to sasl.egg-info\dependency_links.txt
  writing requirements to sasl.egg-info\requires.txt
  writing top-level names to sasl.egg-info\top_level.txt
  reading manifest file 'sasl.egg-info\SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  adding license file 'LICENSE.txt'
  writing manifest file 'sasl.egg-info\SOURCES.txt'
  copying sasl\saslwrapper.cpp -> build\lib.win-amd64-3.9\sasl
  copying sasl\saslwrapper.h -> build\lib.win-amd64-3.9\sasl
  copying sasl\saslwrapper.pyx -> build\lib.win-amd64-3.9\sasl
  running build_ext
  building 'sasl.saslwrapper' extension
  creating build\temp.win-amd64-3.9
  creating build\temp.win-amd64-3.9\Release
  creating build\temp.win-amd64-3.9\Release\sasl
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isasl -IC:\ProgramData\Anaconda3\include -IC:\ProgramData\Anaconda3\include -IC:\Prog
ram Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\ATLMFC\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include -IC:\Program Files (x86)\Windows Kits\10\
include\10.0.19041.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt -IC:\Pr
ogram Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt /EHsc /Tpsasl/saslwrapper.cpp /Fobuild\temp.win-amd64-3.9\Release\sasl/saslwrapper.obj
  saslwrapper.cpp
  D:\users\jingtao.CENTALINE\AppData\Local\Temp\pip-install-2scxm6jd\sasl_bdd59789a4b54e288cc48a38704a6ad4\sasl\saslwrapper.h(22): fatal error C1083: 无法打开包括文件: “sasl/sasl.h”: No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
  ----------------------------------------
  ERROR: Failed building wheel for sasl
  Running setup.py clean for sasl
Failed to build sasl
Installing collected packages: sasl
    Running setup.py install for sasl ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\ProgramData\Anaconda3\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'D:\\users\\jingtao.CENTALINE\\AppData\\Local\\Temp\\pip-install-2scxm6jd\\sasl_bdd59789a4b54e288cc48a38704a6ad4\\se
tup.py'"'"'; __file__='"'"'D:\\users\\jingtao.CENTALINE\\AppData\\Local\\Temp\\pip-install-2scxm6jd\\sasl_bdd59789a4b54e288cc48a38704a6ad4\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__)
 else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'D:\users\jingtao.CENTALINE\AppData\Loca
l\Temp\pip-record-l_ubu2on\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\ProgramData\Anaconda3\Include\sasl'
         cwd: D:\users\jingtao.CENTALINE\AppData\Local\Temp\pip-install-2scxm6jd\sasl_bdd59789a4b54e288cc48a38704a6ad4\
    Complete output (28 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.9
    creating build\lib.win-amd64-3.9\sasl
    copying sasl\__init__.py -> build\lib.win-amd64-3.9\sasl
    running egg_info
    writing sasl.egg-info\PKG-INFO
    writing dependency_links to sasl.egg-info\dependency_links.txt
    writing requirements to sasl.egg-info\requires.txt
    writing top-level names to sasl.egg-info\top_level.txt
    reading manifest file 'sasl.egg-info\SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    adding license file 'LICENSE.txt'
    writing manifest file 'sasl.egg-info\SOURCES.txt'
    copying sasl\saslwrapper.cpp -> build\lib.win-amd64-3.9\sasl
    copying sasl\saslwrapper.h -> build\lib.win-amd64-3.9\sasl
    copying sasl\saslwrapper.pyx -> build\lib.win-amd64-3.9\sasl
    running build_ext
    building 'sasl.saslwrapper' extension
    creating build\temp.win-amd64-3.9
    creating build\temp.win-amd64-3.9\Release
    creating build\temp.win-amd64-3.9\Release\sasl
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isasl -IC:\ProgramData\Anaconda3\include -IC:\ProgramData\Anaconda3\include -IC:\Pr
ogram Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\ATLMFC\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include -IC:\Program Files (x86)\Windows Kits\1
0\include\10.0.19041.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt -IC:\
Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt /EHsc /Tpsasl/saslwrapper.cpp /Fobuild\temp.win-amd64-3.9\Release\sasl/saslwrapper.obj
    saslwrapper.cpp
    D:\users\jingtao.CENTALINE\AppData\Local\Temp\pip-install-2scxm6jd\sasl_bdd59789a4b54e288cc48a38704a6ad4\sasl\saslwrapper.h(22): fatal error C1083: 无法打开包括文件: “sasl/sasl.h”: No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\ProgramData\Anaconda3\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'D:\\users\\jingtao.CENTALINE\\AppData\\Local\\Temp\\pip-install-2scxm6jd\\sasl_bdd
59789a4b54e288cc48a38704a6ad4\\setup.py'"'"'; __file__='"'"'D:\\users\\jingtao.CENTALINE\\AppData\\Local\\Temp\\pip-install-2scxm6jd\\sasl_bdd59789a4b54e288cc48a38704a6ad4\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__fi
le__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'D:\use
rs\jingtao.CENTALINE\AppData\Local\Temp\pip-record-l_ubu2on\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\ProgramData\Anaconda3\Include\sasl' Check the logs for full command output.

 

Solution:
Download a sasl file that corresponds to the Python version and Windows version you are using: https://www.lfd.uci.edu/~gohlke/pythonlibs/#sasl. For example, sasl-0.2.1-cp36 -cp36m-win_amd64.whl, which corresponds to Python version 3.6, and corresponds to Windows system 64-bit.
Install the executable pip install sasl-0.2.1-cp37-cp37m-win_amd64.whl

[Solved] pycocotools Install Error: ERROR: Error expected str, bytes or os.PathLike object, not NoneType while executing

Recently playing detectron2, need pycocotools >= 2.0.2, python version 3.7, installation error

ERROR: Error expected str, bytes or os.PathLike object, not NoneType while executing command pip subprocess to install build dependencies

It is found that pycocotools updated to 2.0.4. The degraded version can be installed normally:

pip install pycocotools==2.0.2

[Solved] theano-GPU Error: pygpu.gpuarray.GpuArrayException: b‘cuMemAlloc: CUDA_ERROR_OUT_OF_MEMORY: out of memory

Project scenario:

l2t code needs to use theano library and GPU to accelerate calculation

Non root user ubuntu-18.04 + cuda8 0 (you need to downgrade GCC to match, I’ll configure it as 5.3) + cudnn V5 1+theano 1.0.4+pygpu 0.7.6


Problem description

pygpu.gpuarray.GpuArrayException: b'cuMemAlloc: CUDA_ERROR_OUT_OF_MEMORY: out of memory
Training... 2448.24 sec.
Traceback (most recent call last):
  File ".../python3.8/site-packages/theano/compile/function_module.py", line 903, in __call__
    self.fn() if output_subset is None else\
  File "pygpu/gpuarray.pyx", line 689, in pygpu.gpuarray.pygpu_zeros
  File "pygpu/gpuarray.pyx", line 700, in pygpu.gpuarray.pygpu_empty
  File "pygpu/gpuarray.pyx", line 301, in pygpu.gpuarray.array_empty
pygpu.gpuarray.GpuArrayException: b'cuMemAlloc: CUDA_ERROR_OUT_OF_MEMORY: out of memory'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "learn.py", line 535, in <module>
    main()
  File "learn.py", line 531, in main
    trainer.train()
  File "..l2t/lib/python3.8/site-packages/smartlearner-0.1.0-py3.8.egg/smartlearner/trainer.py", line 31, in train
  File ../l2t/lib/python3.8/site-packages/smartlearner-0.1.0-py3.8.egg/smartlearner/trainer.py", line 90, in _learning
  File "..l2t/lib/python3.8/site-packages/theano/compile/function_module.py", line 914, in __call__
    gof.link.raise_with_op(
  File "../l2t/lib/python3.8/site-packages/theano/gof/link.py", line 325, in raise_with_op
    reraise(exc_type, exc_value, exc_trace)
  File "../l2t/lib/python3.8/site-packages/six.py", line 718, in reraise
    raise value.with_traceback(tb)
  File "../l2t/lib/python3.8/site-packages/theano/compile/function_module.py", line 903, in __call__
    self.fn() if output_subset is None else\
  File "pygpu/gpuarray.pyx", line 689, in pygpu.gpuarray.pygpu_zeros
  File "pygpu/gpuarray.pyx", line 700, in pygpu.gpuarray.pygpu_empty
  File "pygpu/gpuarray.pyx", line 301, in pygpu.gpuarray.array_empty
pygpu.gpuarray.GpuArrayException: b'cuMemAlloc: CUDA_ERROR_OUT_OF_MEMORY: out of memory'
Apply node that caused the error: GpuAlloc<None>{memset_0=True}(GpuArrayConstant{[[0.]]}, Elemwise{Composite{((i0 * i1 * i2 * i3) // maximum(i3, i4))}}[(0, 0)].0, Shape_i{3}.0)
Toposort index: 98
Inputs types: [GpuArrayType<None>(float64, (True, True)), TensorType(int64, scalar), TensorType(int64, scalar)]
Inputs shapes: [(1, 1), (), ()]
Inputs strides: [(8, 8), (), ()]
Inputs values: [gpuarray.array([[0.]]), array(2383800), array(100)]
Outputs clients: [[forall_inplace,gpu,grad_of_scan_fn}(Shape_i{1}.0, InplaceGpuDimShuffle{0,2,1}.0, InplaceGpuDimShuffle{0,2,1}.0, InplaceGpuDimShuffle{0,2,1}.0, GpuAlloc<None>{memset_0=True}.0, GpuSubtensor{int64:int64:int64}.0, GpuSubtensor{int64:int64:int64}.0, GpuSubtensor{int64:int64:int64}.0, GpuSubtensor{int64:int64:int64}.0, GpuSubtensor{int64:int64:int64}.0, GpuAlloc<None>{memset_0=True}.0, GpuAlloc<None>{memset_0=True}.0, GpuAlloc<None>{memset_0=True}.0, GpuAlloc<None>{memset_0=True}.0, GpuAlloc<None>{memset_0=True}.0, Shape_i{1}.0, Shape_i{1}.0, Shape_i{1}.0, Shape_i{1}.0, Shape_i{1}.0, Shape_i{1}.0, Shape_i{1}.0, Shape_i{1}.0, Shape_i{1}.0, Shape_i{1}.0, GRU0_W, GRU0_U, GRU0_Uh, GRU1_W, GRU1_U, GRU1_Uh, InplaceGpuDimShuffle{x,0}.0, GpuFromHost<None>.0, GpuElemwise{add,no_inplace}.0, GpuElemwise{add,no_inplace}.0, GpuElemwise{Add}[(0, 1)]<gpuarray>.0, GpuReshape{2}.0, GpuFromHost<None>.0, GpuElemwise{add,no_inplace}.0, GpuElemwise{add,no_inplace}.0, GpuElemwise{Add}[(0, 1)]<gpuarray>.0, GpuReshape{2}.0, GpuFromHost<None>.0, GpuElemwise{add,no_inplace}.0, GpuElemwise{add,no_inplace}.0, GpuElemwise{Add}[(0, 1)]<gpuarray>.0, GpuReshape{2}.0, InplaceGpuDimShuffle{1,0}.0, InplaceGpuDimShuffle{1,0}.0, InplaceGpuDimShuffle{x,0}.0, InplaceGpuDimShuffle{1,0}.0, InplaceGpuDimShuffle{1,0}.0, InplaceGpuDimShuffle{1,0}.0, InplaceGpuDimShuffle{1,0}.0, GpuFromHost<None>.0, InplaceGpuDimShuffle{1,0}.0, GpuAlloc<None>{memset_0=True}.0, GpuFromHost<None>.0, GpuAlloc<None>{memset_0=True}.0, GpuFromHost<None>.0, GpuAlloc<None>{memset_0=True}.0)]]
HINT: Re-running with most Theano optimization disabled could give you a back-trace of when this node was created. This can be done with by setting the Theano flag 'optimizer=fast_compile'. If that does not work, Theano optimizations can be disabled with 'optimizer=None'.
HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.

 


Solution:

Reduce gpu__preallocate, I reduced it to 0.8, and optimize it with a small amount of graphs according to the hint when the error is reported


type in the codes

Run successfully!

Raspberry pie Use PCA9685() Error: [Errno 121] Remote I/O error

After I install pca9685() according to the online method, the following errors will appear in the operation.

>>> pwm = Adafruit_PCA9685.PCA9685()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'Adafruit_PCA9685' is not defined
>>> import Adafruit_PCA9685
>>> pwm = Adafruit_PCA9685.PCA9685()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PCA9685-1.0.1-py3.7.egg/Adafruit_PCA9685/PCA9685.py", line 75, in __init__
    self.set_all_pwm(0, 0)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PCA9685-1.0.1-py3.7.egg/Adafruit_PCA9685/PCA9685.py", line 111, in set_all_pwm
    self._device.write8(ALL_LED_ON_L, on & 0xFF)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_GPIO-1.0.4-py3.7.egg/Adafruit_GPIO/I2C.py", line 116, in write8
    self._bus.write_byte_data(self._address, register, value)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO-1.1.9-py3.7.egg/Adafruit_PureIO/smbus.py", line 327, in write_byte_data
OSError: [Errno 121] Remote I/O error

 

But the premise of this method is to have the Adafruit_PCA9685 file under the path /usr/local/lib/python3.7/dist-packages/”, if there is one, use the above method

My Raspberry Pi is 4B, there are three .egg files in the above path, Adafruit_PCA9685 is placed in it, as shown below

Select the middle of the Adafruit_PCA9685 .egg file, there will be PCA9685.py file, just create PCA9685.py under raspberry home/pi/ and paste the contents of the previous PCA9685.py into the newly created file, import the code to import PCA9685 instead of not import Adafruit_PCA9685

import PCA9685

Open the PCA9685 file and find that it needs to import the I2C.py file (I forgot to take a screenshot), then open the first one under the /usr/local/lib/python3.7/dist-packages/ path

Paste the contents of I2C.py and Plaform.py inside this file into a new I2C.py and Plaform.py file under home/pi, then open the PCA9685.py file in this directory and change the imported I2C in the middle position, it seems to be form Adafurit_GPIO import I2C as I2C directly to import I2C.

Then open the I2C file, found that you need to import Plaform.py, the same operation, change the previous import to import Plaform can be, as shown, and finally in the directory I2C.py PCA9685.py and Plaform.py file

You can write it directly in the raspberry pie file

import PCA9685
pwm = PCA9685.PCA9685()

See if it’s successful. I’m successful.

How to Solve word2vec Module Error: AttributeError & UnicodeDecodeError

1. Decode Issues
1. Error Messages: UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xd7 in position 1
2. Error Codes:

Insert # -*- coding: utf8 -*-

def write_review(review, stop_words_address, stop_address, no_stop_address):
    """Write out the processed data"""
    no_stop_review = remove_stop_words(review, stop_words_address)
    with open(no_stop_address, 'a') as f:
        for row in no_stop_review:
            f.write(row[-1])
            f.write("\n")
    f.close()


if __name__ == '__main__':
    segment_text = cut_words('audito_whole.csv')
    review_text = remove_punctuation(segment_text)
    write_review(review_text, 'stop_words.txt', 'no_stop.txt', 'stop.txt')

    # Model Training Master Program
    logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
    sentences_1 = word2vec.LineSentence('no_stop.txt')
    model_1 = word2vec.Word2Vec(sentences_1)

    # model.wv.save_word2vec_format('test_01.model.txt', 'test_01.vocab.txt', binary=False)  # 保存模型,后面可直接调用
    # model = word2vec.Word2Vec.load("test_01.model")  # Calling the model

    # Calculate the list of related words for a word
    a_1 = model_1.wv.most_similar(u"Kongjian", topn=20)
    print(a_1)

    # Calculate the correlation of two words
    b_1 = model_1.wv.similarity(u"Kongjian", u"Houzuo")
    print(b_1)

3. Error parsing: this error means that the character encoded as 0xd7 cannot be parsed during decoding. This is because the encoding method is not specified when saving the text, so the GBK encoding may be used when saving the text
4. Solution: when writing out the data, point out that the coding format is UTF-8, as shown in the following figure

def write_review(review, stop_words_address, stop_address, no_stop_address):
    """Write out the processed data"""
    with open(stop_address, 'a', encoding='utf-8') as f:
        for row in review:
            f.write(row[-1])
            f.write("\n")
    f.close()

    no_stop_review = remove_stop_words(review, stop_words_address)
    with open(no_stop_address, 'a', encoding='utf-8') as f:
        for row in no_stop_review:
            f.write(row[-1])
            f.write("\n")
    f.close()

5. Expansion – why did this mistake happen
first of all, we click the source code file of the error report, as shown in the following figure:
open utils, and we find the following code

it can be seen that the encoding format set by word2vec is UTF-8. If it is not UTF-8 during decoding, errors = ‘strict’ will be triggered, and then UnicodeDecodeError will be reported

2. Attribute error
1 Error reporting: attributeerror: ‘word2vec’ object has no attribute ‘most_similar’
2. Wrong source code:

 # Model Training Master Program
    logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
    sentences_1 = word2vec.LineSentence('no_stop.txt')
    model_1 = word2vec.Word2Vec(sentences_1)

    # model.wv.save_word2vec_format('test_01.model.txt', 'test_01.vocab.txt', binary=False)  # 保存模型,后面可直接调用
    # model = word2vec.Word2Vec.load("test_01.model")  # Calling the model

    # Calculate the list of related words for a word
    a_1 = model_1.most_similar(u"Kongjian", topn=20)
    print(a_1)

**3. Analysis of error reports: * * error reports refer to attribute errors because the source code structure has been updated in the new word2vec. See the official website for instructions as follows:

**4. Solution: * * replace the called object as follows:

 # Model Training Master Program
    logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
    sentences_1 = word2vec.LineSentence('no_stop.txt')
    model_1 = word2vec.Word2Vec(sentences_1)

    # model.wv.save_word2vec_format('test_01.model.txt', 'test_01.vocab.txt', binary=False)  # 保存模型,后面可直接调用
    # model = word2vec.Word2Vec.load("test_01.model")  # Calling the model

    # Calculate the list of related words for a word
    a_1 = model_1.wv.most_similar(u"Kongjian", topn=20)
    print(a_1)

5. Why is model_1.wv.most_similar(), I didn’t find the statement about WV definition in word2vec. Does anyone know?

[Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘map‘

AttributeError: ‘XXX’ object has no attribute ‘map’

Objects that meet the map format need to be in the form of key value pairs, so check whether the elements using the map function meet this condition.

For example:

#Create an object of DataFrame
list=[[1,1],[2,2]]
list=pd.DataFrame(list)
print(list)

#Use map to map them
for _, row in list.iterrows():
    row[0]=row[0].map(lambda a:a+1)

Output:

correct method:

list=[[1,1],[2,2]]
list=pd.DataFrame(list)
print(list)

list[0]=list[0].map(lambda a:a+1)
print(list)

Output:

[Solved] Pycharm Use pip to install package error: no such option –build-dir

Pychar reports an error when using PIP to install the package. No such option — build dir

    1. reason: the PIP version is too high.
    1. Solution: downgrade the pip version and wait for the update of pycharm

open the command line, find the location of Python and enter: 

PIP install PIP = = 20.2.4
set the PIP version to 20.2.4

if no variable is set for PIP, Check the location of Python in settings->python Interpreter

and then execute the following command on the command line </ OL>

/usr/local/bin/python3. 8 -m pip install pip==20.2.4

[Solved] Python pytesseract(tesseract OCR) Error: TesseractNotFoundError

Error when running code

Use PIP install pytesseract

pip install tesseract

It still doesn’t work after installation. The same error is reported

Subsequent error finding:

Testseract-ocr is not installed

OCR (Optical Character Recognition): Optical Character Recognition, which refers to the process of analyzing, recognizing, and acquiring text in image files.
Tesseract: An open source OCR recognition engine. The initial Tesseract engine was developed by HP Labs, and later contributed to the open source software industry, and was later improved by Google to eliminate bugs, optimize, and re-release.

http://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-setup-4.00.00dev.exe Can be downloaded

After installation, add before the error code

pytesseract.pytesseract.tesseract_cmd = 'E:\\software\\Tesseract-OCR\\tesseract.exe'

This is followed by the path to install Tesseract-ocr

Successfully solved.

[Solved] mmdetection Error: ImportError: /home/user/repos/mmdetection/mmdet/ops/dcn/deform_conv_cuda.cpython-37m-x

Environment configuration: torch 1.11.0 + CUDA 11.3 (latest)

Use mmdetection to infer:

from mmdet.apis import init_detector, inference_detector

Errors are reported as follows:

ImportError: /home/user/repos/mmdetection/mmdet/ops/dcn/deform_conv_cuda.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZN6caffe26detail37_typeMetaDataInstance_preallocated_32E

 

The problem has been solved. The reason for the error is that the pytorch version is too new. Although openmmlab supports the latest version, it will still cause the error.

Solution:

Degrade the pytorch version to torch 1.6.0 + cu102, query the official GitHub of openmmlab, uninstall and reinstall mmcv 1.3.9, and re run the mmdetection code to solve the error.