Tag Archives: Machine learning

When writing teacher Wu Enda’s machine learning class, there was a problem with the result of using scipy.optimize.fmin_cg

Tips for training Completion:

Warning: Desired error not necessarily achieved due to precision loss.
         Current function value:

The reason is I in front of def computeCost (myTheta myX, myy, mylambda = 0.) : # cost function first parameter myTheta write wrong, right should be myTheta… This problem has been looking for an hour, sad, it is good to change

An error occurred when running ROCR: Failed to load the package ‘caTools’, package or namespace load failed

If it helps, thank thumb up for the encouragement
The environment is win10+R3.6.3
, the problem has been solved, and the Error is reported as follows:
loading required package: gplot Error: package or namespace load failed for 'gplot' in loadNamespace(j < -i [[1L]], c(lib.loc,.libpaths (), versionCheck = vI[[j]): there is no package error called 'caTools' : failed to load the package' gpaths '
There has been a problem this morning, which is strange. CaTools could not be installed in Rstudio and I have already packed the plots, so I guess it’s caTools’ problem.

    USES general method one, not ok:
    directly click Rstudio, click install and then enter caTools is not ok. Use method 2, no:
install.packages("caTools")
    use method three, first download the resources and then local installation, successfully solved.

First find caTools resource location, address is as follows:
https://cran.r-project.org/web/packages/caTools/
and then on the page, right click to get the resource bundle links, return to Rstudio, enter the following two lines of code, run successfully solve the problem of caTools installation.

packageurl <- "https://cran.r-project.org/bin/windows/contrib/4.0/caTools_1.18.0.zip"

install.packages(packageurl, repos=NULL, type="source")

It should be added that if a package has not been installed, baidu searches for the package, such as "R installs caTools". We then see if our dependent packages are configured so that we can have a second way to look at them, in addition to the ones that the console output lacks.
Refer to the blog:
https://blog.csdn.net/ARPOSPF/article/details/84997200 https://blog.csdn.net/zdx1996/article/details/86629965

Error: cudaGetDevice() failed. Status: CUDA driver version is insufficient for CUDA runtime version

… Status: CUDA driver version is insufficient for CUDA runtime version

may be cuda and video card drivers are inconsistent

CUDA version with video card driver version match query: https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html

Cuda version number query: nvcc-v

view graphics driver: cat/proc/driver/nvidia/version

driver version and cuda version no problem

may also be a conflict between the TensorFlow version and cuda version:

tensorflow version number query:

query TensorFlow corresponds to cuda version:

Windows side

https://tensorflow.google.cn/install/source_windows

Linux:

https://tensorflow.google.cn/install/source

final solution: lower the TensorFlow version


reference: http://www.cnblogs.com/liaohuiqiang/archive/2018/10/15/9791365.html

https://blog.csdn.net/qq_30163461/article/details/80314630

wish India and Pakistan peace, every day there are strawberries to eat

Use NVIDIA to solve NVIDIA’s

used to display memory usage successfully using the nvidia-smi command, but not recently,
NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running. And others said it is ok to install the driver again, these are not solve my problem, actually very simple question because ubutnu kernel update, a new version of the kernel and graphics driver does not match the above problems, we need only when making ubuntu startup guide interface, is just began to call you to select the operating system interface, select “ubuntu advanced options”, select a previous version of the kernel, is the new version of my 4.15.0-43 – generic
I then chose 4.15.0-42 – generic version, Then enter the system and use the nvidia-SMi command to execute successfully.
you can view the current ubuntu kernel version

using the following command

>uname -r

Python opencv (3) get image size

The shape attribute of the image matrix

represents the size of the image, and shape returns the tuple tuple. The first element represents the number of rows of the matrix, the second tuple represents the number of columns of the matrix, and the third element is 3, indicating that the pixel value consists of the three primary colors of light.

import cv2
import numpy as np
fn="baboon.jpg"
if __name__ == '__main__':
    print 'load %s as ...' % fn
    img = cv2.imread(fn)
    sp = img.shape
    print sp
    sz1 = sp[0]#height(rows) of image
    sz2 = sp[1]#width(colums) of image
    sz3 = sp[2]#the pixels value is made up of three primary colors
    print 'width: %d \nheight: %d \nnumber: %d' %(sz1,sz2,sz3)

运行结果:
加载baboon.jpg…

(512、512、3)宽度:512
身高:512年
数字:3

Derivation process of gradient descent method based on house price

recall that in the previous section, we introduced the house-price based modeling under a single variable, the cost function, and the design of the gradient descent method. In this section, we extended the problem to the generalization, and how to deduce the gradient descent process under the change of a single variable into a multiple variable.

As shown in the figure, the input features are (x1,x2,x3,x4)

The output feature of

is y

The total number of samples

is m

It’s

and we’re assuming that the fitting function is

, then we want to minimize the cost function, the solution of the parameter is shown in the figure

in order to understand the cost function when there are only two variables, the cost function is shown in the figure

X1 = size (0-2000)

X2 = bedroom (0-5)

by observing the left figure, we find that when x1 and x2 are greatly different, the cost function image is of thin and tall shape. In this case, the route of gradient descent to the optimal solution is more tortuous, that is, the regression is more difficult. When the parameters are relatively close, as shown in the right figure, the gradient descent route is closer to a linear line, that is, the gradient descent is easier.

so we need to scale the feature

scale to [0-1] feature/ the total of number

method 2 scales to [-1, 1] (feature – mean)/the total of number

, of course, as shown in the figure, if the parameters are not far apart, such as between [-3, 3], there is no need to scale the feature

in the previous section, we talked about the effect of a on regression in the case of gradient descent, and then we specifically discuss the value of a

through the previous observation, we found that in order to find the parameters of the hypothesis function, we need to update the parameters step by step, and then introduce another solution method (through mathematical reasoning method: normal equation, one step in place to find the optimal parameter)

let’s look at this formula, X is a row vector, (XTX) is an n by n matrix, and solving its inverse requires order n3 complexity, so we don’t use this method when we have more features.

Pytorch — nn.Sequential () module

In short, nn.Sequential() packs a series of operations into , which could include Conv2d(), ReLU(), Maxpool2d(), etc., which could be packaged to be invoked at any point, but would be a black box, which would be invoked at forward().

extract part of the AlexNet code to understand sequential:

class AlexNet(nn.Module):
    def __init__(self, num_classes=1000, init_weights=False):
        super(AlexNet, self).__init__()
        
        self.features = nn.Sequential(
            nn.Conv2d(3, 48, kernel_size=11, stride=4, padding=2),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=3, stride=2), 
            nn.Conv2d(48, 128, kernel_size=5, padding=2),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=3, stride=2),
            nn.Conv2d(128, 192, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(192, 192, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(192, 128, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=3, stride=2),
        )
        ......
        
    def forward(self, x):
        x = self.features(x)
        ......
        return x

init__, self. Features = nn.Sequential(…)

in forward() just use self.features(x) to

tensorflow2.1 Error:Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR

system environment :

OS: UBUNTU18.04
CUDA:10.1
Tensorflow 2.1
cuDNN: 7.6.5
TensorRT: 6.0.15(tf2.1 supports TensorRT6.0)
GPU: RTX2080(8G)*2

use the new version tensorflow (2.1 support CUDA version 10.1, 2.0 supports version 10.0), appeared the following error (error repetition code address: https://github.com/keras-team/keras/blob/master/examples/cifar10_cnn.py) : </ p>

2020-01-16 21:49:19.892263: E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
2020-01-16 21:49:19.897303: E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
2020-01-16 21:49:19.897396: W tensorflow/core/common_runtime/base_collective_executor.cc:217] BaseCollectiveExecutor::StartAbort Unknown: 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 conv2d_1/convolution}}]]


Through the discussion of issues in tensorflow library, we know that the problem is on the video memory allocation of rtx2070/2080 graphics card. According to the method mentioned in issues, add the following code at the beginning of the program :

# gpus= tf.config.experimental.list_physical_devices('GPU')
gpus= tf.config.list_physical_devices('GPU') # tf2.1版本该函数不再是experimental
print(gpus) # 前面限定了只使用GPU1(索引是从0开始的,本机有2张RTX2080显卡)
tf.config.experimental.set_memory_growth(gpus[0], True) # 其实gpus本身就只有一个元素

but in my own context there is another error :

ValueError: Memory growth cannot differ between GPU devices

look at the hint should be the cause of conflict between gpus, so I try to use only one GPU:

import os
os.environ['CUDA_VISIBLE_DEVICES']='1' 

, this will solve the error