Author Archives: Robins

Kubernetes reported an error: matchexpressions: [] v1. Labelselector requirement (NIL)}: field is immutable

error message

MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable

Reason

reason: the essential reason for this problem is that two identical Deployment (one deployed and one to deploy) have different selectors.

scene duplicate

case:
app.yaml

apiVersion: apps/v1                                                                  kind: Deployment
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  replicas: 10
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
        version: v1.0.0
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9101"
    spec:
      containers:
      - name: my-app
        image: containersol/k8s-deployment-strategies
        ports:
        - name: http
          containerPort: 8080
        - name: probe
          containerPort: 8086
        env:
        - name: VERSION
          value: v1.0.0
        livenessProbe:
          httpGet:
            path: /live
            port: probe
          initialDelaySeconds: 5
          periodSeconds: 5
        readinessProbe:
          httpGet:
            path: /ready
            port: probe
          periodSeconds: 5

after deployment, take a look at the results

$kubectl get deployment
NAME     READY   UP-TO-DATE   AVAILABLE   AGE
my-app   10/10   10           10          84s

Next, we modify the selector of deployment, which mainly reads </p b>

spec:
  replicas: 10
  selector:
    matchLabels:
      app: my-app-change
  template:
    metadata:
      labels:
        app: my-app-change
        version: v1.0.0

the completion file is as follows :

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  replicas: 10
  selector:
    matchLabels:
      app: my-app-change
  template:
    metadata:
      labels:
        app: my-app-change
        version: v1.0.0
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9101"
    spec:
      containers:
      - name: my-app
        image: containersol/k8s-deployment-strategies
        ports:
        - name: http
          containerPort: 8080
        - name: probe
          containerPort: 8086
        env:
        - name: VERSION
          value: v1.0.0
        livenessProbe:
          httpGet:
            path: /live
            port: probe
          initialDelaySeconds: 5
          periodSeconds: 5
        readinessProbe:
          httpGet:
            path: /ready
            port: probe
          periodSeconds: 5

When kubectl is deployed, the following error occurs:

$kubectl apply -f app.yaml
The Deployment "my-app" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app":"my-app-change"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable

and you can see the selector for deployed:

$kubectl describe deployment my-app
Name:                   my-app
...
Selector:               app=my-app
...

you can see that the deployment name my-app already has a selector and the content is app=my-app. At this time, the reason for the error is that the name of the newly deployed deployment is also MY-app, but the content of the selector is APP = My-app-change.

solution:

1: you can delete the original deployment and then deploy
2: modify the name of deployment instead of repeating

How to use torch.sum()

torch. Sum () sums up one dimension of the input tensor data, which are divided into two forms:

1.torch.sum(input, dtype=None)
2.torch.sum(input, list: dim, bool: keepdim=False, dtype=None) → Tensor
 
input:输入一个tensor
dim:要求和的维度,可以是一个列表
keepdim:求和之后这个dim的元素个数为1,所以要被去掉,如果要保留这个维度,则应当keepdim=True
#If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. 

example:

a = torch.ones((2, 3))
print(a):
tensor([[1, 1, 1],
 		[1, 1, 1]])

a1 =  torch.sum(a)
a2 =  torch.sum(a, dim=0)
a3 =  torch.sum(a, dim=1)

print(a)
print(a1)
print(a2)

output:

tensor(6.)
tensor([2., 2., 2.])
tensor([3., 3.])

if you add keepdim=True, the dim dimension is kept from being squeezed

a1 =  torch.sum(a, dim=(0, 1), keepdim=True)
a2 =  torch.sum(a, dim=(0, ), keepdim=True)
a3 =  torch.sum(a, dim=(1, ), keepdim=True)

output:

tensor([[6.]])
tensor([[2., 2., 2.]])
tensor([[3., 3.]])

</ div>

torch.cuda.is_ Available() returns false

1, problem

after the torch gpu version is installed, torch.cuda.is_available() always returns False; But the execution of the torch. Backends. Cudnn. Enabled is TRUE.

execute nvidia-smi command without error, can display the driver information;

on the Internet, search the solution: execute the command:

sudo apt-get install nvidia-cuda-toolkit

still gives an error.

2, problem analysis

try various way, or still returns False, normal if installed correctly, return TRUE, the problem is that version of the problem, either a video card driver versions do not match, either install packages do not match.

3. Solution:

(1) method 1: update the video card driver. This method is risky and troublesome to operate, so it is not recommended.

(2) method two: find the corresponding version of cudatoolkit for installation: the specific version of each driver support, as follows:

https://docs.nvidia.com/deploy/cuda-compatibility/#binary-compatibility

installation method:

 conda install pytorch torchvision cudatoolkit=xxx(选择对应的版本) -c pytorch


Get picture captcha with Python + Chrome

.

we’ll start by importing some libraries that we’ll use in our code:

import re  # 正则
import time  # 代码停顿执行
from selenium import webdriver  # 打开访问的网站
from PIL import Image  # 图片 安装PIL --> Pillow
import pytesseract  # 图片转文字

(if the above some library file is not installed, can be used in the terminal PIP command to install, or for installation in pyCharm oh, you can refer to https://blog.csdn.net/YuanLiYin079/article/details/108726138, the installation method of selenium in the article to try)

to get the captcha, we need to go to the browser we are going to visit (in this case, using the Google browser)

# chromedriver.exe文件放置的路径(根据自己的路径做适当的修改)
chrome_driver = r"C:\Users\Admin\AppData\Local\Programs\Python\Python37\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe"
driver = webdriver.Chrome(executable_path=chrome_driver)
driver.maximize_window()
driver.implicitly_wait(3)  # 等待3秒
login_url = 'https://我们要访问的登录页面的地址写在这里哦.com'
# 进入访问地址的登录页面
driver.get(login_url)
time.sleep(3)

enter the page, start to get the captcha!

# 获取图片验证码
# 1、全屏截图,设置要将图片放置的路径
driver.save_screenshot('D:\Python_work\images\image.png')
# 2、获取图片验证码坐标和大小
code_image = driver.find_element_by_class_name('verifyCodeImg')
code_location = code_image.location
code_image_size = code_image.size
time.sleep(2)
print("验证码的坐标为:", code_location)  # 控制台查看{'x': 716, 'y': 475}
print("验证码的大小为:", code_image_size)  # 图片大小{'height': 48, 'width': 140}

# 3、图片4个点的坐标位置
left = code_image.location['x']  # x点的坐标
top = code_image.location['y']  # y点的坐标
right = left + code_image.size['width']  # 上面右边点的坐标
Rdown = top + code_image.size['height']   # 下面右边点的坐标
image = Image.open('D:\Python_work\images\image.png')

# 4、将图片验证码截取
code_image = image.crop((left, top, right, Rdown))
code_image.save('D:\Python_work\images\image1.png')  # 截取的验证码图片保存为新的文件
codeStr = pytesseract.image_to_string(code_image)  # 图片转文字
# 5、去除识别出来的特殊字符
codeStrS = re.sub(u"([^\u4e00-\u9fa5\u0030-\u0039\u0041-\u005a\u0061-\u007a])", "", codeStr)
result_four = codeStrS[0:4]  # 只获取前4个字符
print(codeStrS)  # 打印识别的验证码

now we can see the obtained captcha we printed out in the console, perform your input operation, and see what happens!


install pytesseract,
download the tesseract_ocr file from https://github.com/UB-Mannheim/tesseract/wiki, install:
remember the path to install because it will be used later.


then, open found an error, open the pytesseract. Py files, Find tesseract_cmd, comment out the original, and add a new one: tesseract_cMD = “path /tesseract.exe”. Then execute the code, and it will execute successfully.

No value has been specified for this provider

The project on github has encountered a problem for the first time:

No value has been specified for this provider

remove Settings. Include “xxxapp” in gradle and then File-> Sync project with gradles

Settings. Gradle include “xxxapp” and then File-> Sync project with gradles

https://www.jianshu.com/p/25c57ba7421a

met Unable to resolve the dependency for ‘: app @ the debug/compileClasspath: Could not resolve com. Google. Android. The GMS: play – services – basement: [15.0.0, 16.0.0)

Tensorflow 2.1.0 error resolution: failed call to cuinit: CUDA_ ERROR_ NO_ DEVICE: no CUDA-capable device is detected

today in the use of keras-gpu in jupyter notebook error, at first did not pay attention to the console output, only from jupyter see error messages. So, check the solution, roughly divided into two, one version back, two specified running equipment. Because I felt that it was not the version problem, I still used the latest version without going back, so I tried the second method to solve the problem, that is, the program was designed to run the device, and the program could run without error. I accidentally noticed the console output and found that the CPU was running?Then found that the name of the specified device error, resulting in the system can not find the device, so first query the name of the device and then specify the device, to solve the problem.


native environment:

  • cudatoolkit = 10.1.243
  • cudnn = 7.6.5
  • tensorflow – gpu = 2.1.0
  • keras – gpu = 2.3.1

Jupyter notebook print error:

...
UnknownError:  Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
	 [[node time_distributed_1/convolution (defined at C:\anaconda3\envs\keras\lib\site-packages\keras\backend\tensorflow_backend.py:3009) ]] [Op:__inference_keras_scratch_graph_1967]

Function call stack:
keras_scratch_graph

Jupyter notebook console print error: failed call to cuInit: CUDA_ERROR_NO_DEVICE: no cuda-capable device is detected


solution:

  1. to view native GPU/CPU information
from tensorflow.python.client import device_lib
device_lib.list_local_devices()

output:

[name: "/device:CPU:0"
 device_type: "CPU"
 memory_limit: 268435456
 locality {
 }
 incarnation: 16677593686354176255,
 name: "/device:GPU:0"
 device_type: "GPU"
 memory_limit: 1440405913
 locality {
   bus_id: 1
   links {
   }
 }
  incarnation: 787265797177696422
 physical_device_desc: "device: 0, name: GeForce 940MX, pci bus id: 0000:01:00.0, compute capability: 5.0"]
  1. can see that the native device has GPU, so use the following statement to specify the name of the running device:
    The attention! = The following must be the device name, each person’s device name may be different, do not copy, must first use the command query, then specify!
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '/device:GPU:0'
  1. to view the currently loaded device:
import tensorflow as tf
sess = tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(log_device_placement=True))

output:

Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce 940MX, pci bus id: 0000:01:00.0, compute capability: 5.0
  1. console output similar to the following information explains that the code has been run on the GPU:

Python 3 uses the relative path import module

directory structure

.
├ ─ ─ apt_root. Py
├ ─ ─ just set p y
├ ─ ─ mod/
└ ─ ─ test. Py
└ ─ ─ just set p y
└ ─ ─ sub/
└ ─ ─ test. Py
└ ─ ─ just set p y

task 1: import apt_root.py

from the parent directory in mod/test.py

task 2: import the sub/test.py

from the parent directory in mod/test.py

if

. Why does the title restrict the import of python3?

because all the peps you can find on the web are python2. Such as PEP328. But as far as I can see, python2 and python3 have different import rules.

absolute path is not good, why restrict to relative path import module?

refers to the module through the absolute path, which can easily cause a lot of work when the code structure is changed later, or when the file is renamed. Relative paths don’t have this problem


Analytical

one of the starting points of this article is that I found import is not easy, at least it caused a lot of confusion for me, so I share it here, hoping that the above two tasks can cover all the difficult cases. The first is the confusion of executing test.py in different ways, where the import is found to correspond to the module.

in the python form of test.py

in this case, python mod/test.py,

are executed in the root directory

or enter the mod subdirectory and execute python test.py with the same effect.

:

:

from . import apt_root
# 或者
from .. import apt_root
# 或者
from ..apt_root import *

I tested the successful way of writing:

import sys

sys.path.append(".")
import app_root

therefore, there should be one ‘.’ for the next level, and two ‘.’ for the next level. This means to add the previous directory to the search path.

in python-m test mode

, if my import is

import app_root

(as opposed to direct python xxx.py) runs in different directories and has different effects!

1: in the root directory: python-m mod. Test — run successfully

two: enter mod subdirectory first, then python -m test – run failure

if you want it to run successfully, it should look like this:

sys.path.append("..")
import app_root

(another confusing example) python-m XXX, to add the parent directory to the search path, use “..” , unlike python xxx.py, which USES “.” to represent the parent directory!

because python-m adds the path of the current command to sys.path. See python: The Python-m parameter?

therefore, in this method, it is necessary to combine the path of the current command running + the search path in the default sys.path + the newly added path in the code sys.path.append to determine whether the import can be successful.

summary

where it can be confusing:

1. Relative path cannot be used from.. To import XX, use sys.path.append(“..” )

2. Python-m XXX and python xx.py are different in the representation of the parent directory of import, the former USES two dots, the latter USES one;

3. The import search path in python-m XXX is related to the directory where the command is currently executing;

Python xxx.py is independent of the directory in which the command is currently executing


[welcome to follow my WeChat official number: artificial intelligence Beta]

Problem: attributeerror: ‘tensor’ object has no attribute ‘creator’

AttributeError: ‘Tensor’ object has no attribute ‘creator’

according to the official pytorch documentation, the variable has the above three properties, but the error of not having this property appears when the creator property of the y operation is obtained.

import torch
from torch.autograd import Variable
x = Variable(torch.ones(1,3), requires_grad=True)
y = x+2
print('x: ', x)
print('y: ', y)
print(y.creator)

after checking, it is found that the name of creator property has been changed to grad_fn, and many documents have not been modified

on making commits: https://github.com/pytorch/tutorials/pull/91/files

after modification, run again, you can get the property Variable

of the created Function property of y

import torch
from torch.autograd import Variable
x = Variable(torch.ones(1,3), requires_grad=True)
y = x+2
print('x: ', x)
print('y: ', y)
print(y.grad_fn)

How to delete Microsoft AutoUpdate from Mac

how to remove Microsoft AutoUpdate from Mac

how to remove Microsoft AutoUpdate from Mac

want to remove Microsoft AutoUpdate from Mac?Maybe you uninstalled Microsoft Office or some other Microsoft application from the Mac, so you no longer need Microsoft applications to automatically update themselves. In any case, you can remove the Microsoft AutoUpdate application from the Mac OS.

if Microsoft AutoUpdate is currently running, you need to exit the application first. You can also force an exit from the Microsoft AutoUpdate application from the activity monitor if desired.

From the MacOS Finder, pull down the “Go” menu and select “Go To Folder” (or press Command + Shift + G) and enter the following path:
/Library/Application Support/Microsoft/

find the folder named “MAU” or “MAU2.0”, then open that directory
find and drag “Microsoft autoupdate.app” to the wastepaper basket

After closing the MAU folder and continuing to use Mac as usual
to delete Microsoft AutoUpdate, Microsoft AutoUpdate will no longer run or automatically run on the Mac to update the software.

if you still want to own and use on the Mac Microsoft applications, deleting Microsoft AutoUpdate application may result in some unexpected consequences, in addition to get outdated software from Microsoft, so if you are a heavy Microsoft software users, it is best not to delete it, Microsoft Office, Word, Outlook, PowerPoint, Excel, Edge or any other things.

* if you want to leave other items in deleted messages for the time being, you can also specifically delete the file from deleted messages.

if you know of any other ways to manage, tame, or remove Microsoft AutoUpdate applications on a Mac, please share them in the comments below!

Datagrip import & export table structure and data

right click directly next to the database you want to export and select dump with ‘mysqldump’

mysqldump是mysql用于转存储数据库的实用程序。

add the -d argument to the automatically generated command to export only the table structure without the data! if you want to export a file containing data, plus the -d parameter can be broken…

if the local mysqldump version is higher, for example, my local version is 8.0 and the target data source version is lower, the export will fail :

mysqldump: Couldn't execute 'SELECT COLUMN......

solution: add –column-statistics=0 to solve the problem

if you want to export the entire database that contains the data; Alternatively, use the command

at terminal

mysqldump -u root -p source1 > source2.sql

where source1 is the name of the database to be exported and

is the data name of the exported source.sql

import the exported source2.sql into the database using the following command :

/source/XXX XXX source2. SQL

where source2.sql is the data to be imported

before import , first to enter mysql, then to build a database, such as database, then into the database, finally execute the above command can be