Tag Archives: artificial intelligence

Error: Discrete value supplied to continuous scale [How to Solve]

 

#Simulation data

df <- structure(list(`10` = c(0, 0, 0, 0, 0, 0), `33.95` = c(0, 0, 
0, 0, 0, 0), `58.66` = c(0, 0, 0, 0, 0, 0), `84.42` = c(0, 0, 
0, 0, 0, 0), `110.21` = c(0, 0, 0, 0, 0, 0), `134.16` = c(0, 
0, 0, 0, 0, 0), `164.69` = c(0, 0, 0, 0, 0, 0), `199.1` = c(0, 
0, 0, 0, 0, 0), `234.35` = c(0, 0, 0, 0, 0, 0), `257.19` = c(0, 
0, 0, 0, 0, 0), `361.84` = c(0, 0, 0, 0, 0, 0), `432.74` = c(0, 
0, 0, 0, 0, 0), `506.34` = c(1, 0, 0, 0, 0, 0), `581.46` = c(0, 
0, 0, 0, 0, 0), `651.71` = c(0, 0, 0, 0, 0, 0), `732.59` = c(0, 
0, 0, 0, 0, 1), `817.56` = c(0, 0, 0, 1, 0, 0), `896.24` = c(0, 
0, 0, 0, 0, 0), `971.77` = c(0, 1, 1, 1, 0, 1), `1038.91` = c(0, 
0, 0, 0, 0, 0), MW = c(3.9, 6.4, 7.4, 8.1, 9, 9.4)), .Names = c("10", 
"33.95", "58.66", "84.42", "110.21", "134.16", "164.69", "199.1", 
"234.35", "257.19", "361.84", "432.74", "506.34", "581.46", "651.71", 
"732.59", "817.56", "896.24", "971.77", "1038.91", "MW"), row.names = c("Merc", 
"Peug", "Fera", "Fiat", "Opel", "Volv"
), class = "data.frame")


df

Question:

library(reshape)

## Plotting
meltDF = melt(df, id.vars = 'MW')
ggplot(meltDF[meltDF$value == 1,]) + geom_point(aes(x = MW, y = variable)) +
  scale_x_continuous(limits=c(0, 1200), breaks=c(0, 400, 800, 1200)) +
  scale_y_continuous(limits=c(0, 1200), breaks=c(0, 400, 800, 1200))

Solution:

After the meltdf variable is defined, the factor variable can be transformed into numerical white energy;

If x is a numeric value, add scale_x_continual(); If x is a character/factor, add scale_x_discreate().

meltDF$variable=as.numeric(levels(meltDF$variable))[meltDF$variable]


ggplot(meltDF[meltDF$value == 1,]) + geom_point(aes(x = MW, y =   variable)) +
     scale_x_continuous(limits=c(0, 1200), breaks=c(0, 400, 800, 1200)) +
     scale_y_continuous(limits=c(0, 1200), breaks=c(0, 400, 800, 1200))

Full Error Messages:
> library(reshape)
>
> ## Plotting
> meltDF = melt(df, id.vars = ‘MW’)
> ggplot(meltDF[meltDF$value == 1,]) + geom_point(aes(x = MW, y = variable)) +
+     scale_x_continuous(limits=c(0, 1200), breaks=c(0, 400, 800, 1200)) +
+     scale_y_continuous(limits=c(0, 1200), breaks=c(0, 400, 800, 1200))
Error: Discrete value supplied to continuous scale
>

[Solved] Keras Error: KeyError: ‘accuracy‘, KeyError: ‘val_acc‘, KeyError: ‘acc‘

Problem:
keyerror ‘ACC’ is reported when using keras

Reason:
this is a keras version problem. ACC and accuracy are intended to be the same, but different keras versions use different names, so they need to be replaced. val_ So is acc.

Solution:
Print history keyword
Print (history. History. Keys())
change the error part to the printed “K” and “V”“

[Pytorch Error Solution] Pytorch distributed RuntimeError: Address already in use

The errors reported by pytoch are as follows:

Pytorch distributed RuntimeError: Address already in use

reason:

The port is occupied during model multi card training. Just change the port.

Solution:

Add a parameter — master before running the command_ For example:

 --master_port 29501

The following parameter 29501 can be set to any other port

be careful:

This parameter should be loaded in front of xxx.py, for example:

CUDA_VISIBLE_DEVICES=2,7 python3 -m torch.distributed.run /
--nproc_per_node 2  --master_port 29501  train.py 

ERROR: dependencies ‘curl’, ‘openssl’ are not available for package ‘httr’

ERROR: dependencies ‘curl’, ‘openssl’ are not available for package ‘httr’
removing ‘/usr/local/lib/R/site-library/httr’

apt-get install openssl
apt-get install openssl-devel

apt-get install libcurl

Or:

wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz

tar -xvf  openssl-1.1.1i.tar.gz

cd openssl-1.1.1i/

./config 

make && make install

./config shared 

make clean

make  && make install

‘curl’:

wget  http://curl.haxx.se/download/curl-7.38.0.tar.gz

tar -xzvf curl-7.38.0.tar.gz

cd curl-7.38.0

./configure

make

make install

Resolve – keyerror encountered while installing tensorflow GPU: ‘tensorflow’ error


1. Error content

the error is as follows (example):

ERROR: Exception:
Traceback (most recent call last):
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/resolvelib/resolvers.py", line 171, in _merge_into_criterion
    crit = self.state.criteria[name]
KeyError: 'numpy'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 438, in _error_catcher
    yield
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 519, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/http/client.py", line 463, in read
    n = self.readinto(b)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/http/client.py", line 507, in readinto
    n = self.fp.readinto(b)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/ssl.py", line 1012, in recv_into
    return self.read(nbytes, buffer)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/ssl.py", line 874, in read
    return self._sslobj.read(len, buffer)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/ssl.py", line 631, in read
    v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 189, in _main
    status = self.run(options, args)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_internal/cli/req_command.py", line 178, in wrapper
    return func(self, options, args)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_internal/commands/install.py", line 317, in run
    reqs, check_supported_wheels=not options.target_dir
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 122, in resolve
    requirements, max_rounds=try_to_avoid_resolution_too_deep,
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/resolvelib/resolvers.py", line 453, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/resolvelib/resolvers.py", line 347, in resolve
    failure_causes = self._attempt_to_pin_criterion(name, criterion)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/resolvelib/resolvers.py", line 207, in _attempt_to_pin_criterion
    criteria = self._get_criteria_to_update(candidate)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/resolvelib/resolvers.py", line 199, in _get_criteria_to_update
    name, crit = self._merge_into_criterion(r, parent=candidate)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/resolvelib/resolvers.py", line 173, in _merge_into_criterion

2. Solutions

the input code is as follows:

pip install tensorflow-gpu==1.8.0 --default-timeout=10000 --upgrade

Summary

accumulate more in peacetime and make fewer mistakes in wartime! It’s over

[Solved] TF2.4 Error: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize

First, check whether the CUDA version and cudnn version are aligned.

Version number view:

Note that CUDA indicates the minimum compatibility. For example, version 2.4 and above 11.0 are OK. My side is 11.5, and there is no problem

The error on my side is caused by insufficient video memory

For the error of insufficient video memory, add the following code.

import tensorflow as tf
config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.compat.v1.InteractiveSession(config=config)

[Solved] pycuda._driver.LogicError: cuFuncSetBlockShape failed: invalid resource handle

Invalid resource handle error in pycuda code

When running CUDA code, the following error occurs:

File "/mnt/lustre/demo/extract_disp_newtopo/face_registration-master/code/poisson.py", line 147, in blend_gs_cuda
    block = (1024, 1, 1))
  File "/mnt/lustre/miniconda3/envs/pycuda/lib/python3.6/site-packages/pycuda/driver.py", line 436, in function_call
    func._set_block_shape(*block)
pycuda._driver.LogicError: cuFuncSetBlockShape failed: invalid resource handle

Solution:
find the CUDA function part with the problem:

mod = SourceModule("""
			#include <stdint.h>
			__global__ void construct_b(
				const uint8_t* src, const int16_t* u, const int16_t* v,
				float* b,
				int pix_num, int size
			)

You can add any sentence in the following code before the function declaration

src = torch.cuda.ByteTensor(8)# Fill in the numbers at will, and the matrix is also fine, but the data type should be consistent with the data type in C++
b   = torch.cuda.FloatTensor(9)

The complete code is as follows:

src = torch.cuda.ByteTensor(8)
mod = SourceModule("""
			#include <stdint.h>
			__global__ void construct_b(
				const uint8_t* src, const int16_t* u, const int16_t* v,
				float* b,
				int pix_num, int size
			)

The specific reason is unknown because it occurs occasionally.

[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

[Solved] Tensorflow error or keras error and tf.keras error: oom video memory is insufficient

Hint: if you want to see a list of allocated tenants when oom happens, add Report_tensor_allocations_upon_oom to RunOptions for current allocation info.

Problem description

The problems encountered in today’s 50% off cross-validation and grid search are that the amount of data was too large or bitch_ It also occurs when the size is too large, as shown in the figure:
use the command: Watch – N 0.1 NVIDIA SMI in Linux to view the GPU usage

reason

Due to the lack of video memory, but it is not the real lack of video memory, but because TensorFlow has eaten up the video memory, but there is no actual effective utilization. Therefore, the required video memory can be allocated to TensorFlow. (keras based on TensorFlow is also applicable)

Solution:

1. Set small pitch_Size, although it can be used, the indicator does not cure the root cause
2. Manually set the GPU. In train.py:

(1) in tensorflow
import tensorflow as tf
import os

os.environ["CUDA_VISIBLE_DEVICES"] = "0" Specify which GPU to use
config = tf.ConfigProto()
config.gpu_options.allow_growth = True # Allocate video memory on demand
config.gpu_options.per_process_gpu_memory_fraction = 0.4 # Maximum memory usage 40%
session = tf.Session(config=config)) # Create tensorflow session
...
(2) in keras
import tensorflow as tf
from keras.models import Sequential
import os
from keras.backend.tensorflow_backend import set_session ## Different from tf.keras

os.environ["CUDA_VISIBLE_DEVICES"] = "0"
config = tf.ConfigProto()
config.gpu_options.allow_growth = True  # Allocate video memory on demand
set_session(tf.Session(config=config)) # Pass the settings to keras

model = Sequential()
...
(3) in tf.keras
import tensorflow as tf
from tensorflow.keras.models import Sequential

import os
from tensorflow_core.python.keras.backend import set_session # Different from tf.keras

os.environ["CUDA_VISIBLE_DEVICES"] = "0"
config = tf.ConfigProto()
config.gpu_options.allow_growth = True  # Allocate video memory on demand
config.gpu_options.per_process_gpu_memory_fraction = 0.4 # use 40% of the maximum video memory
set_session(tf.Session(config=config)) # Pass the settings to tf.keras

model = Sequential()
...

Supplement:
tf.keras can use data reading multithreading acceleration:

model.fit(x_train,y_train,use_multiprocessing=True, workers=4) # Enable multithreading, using 4 CPUs

Empty session:

from tensorflow import keras
keras.backend.clear_session() 

After emptying, you can continue to create a new session

Raspberry pie startup self startup opencv program script and error analysis

1. Make test script

First, we need to make a script to test whether the self startup is effective.

pi@raspberry :~ $ nano /home/pi/start.sh

The contents of start.sh are as follows:

/usr/bin/python3 /home/pi/GeometryOperations.py

Here, you must pay attention to the use of absolute paths, otherwise there is a probability that the load will fail.

Then add an execution file to the script file

pi@raspberry :~ $ chmod 777 start.sh

Test the script function

pi@raspberry :~ $ ./start.sh

If you observe that the program is running normally, you can continue to the next step

2. Add self start

Modify rc.local file

pi@raspberry :~ $ sudo nano /etc/rc.local

Find exit 0 in the text. The code added before will be executed at startup. Add a line of code before exit 0:

su pi -c “exec /home/pi/start.sh &”

CTRL + O to save, Ctrl + X to exit and restart.

pi@raspberry :~ $ sudo reboot

After restart, the program can run.

3.DEBUG

If the raspberry pie does not respond after restart, you can check the status of RC local through systemctl

pi@raspberry :~ $ sudo systemctl status rc-local

After you go in, you can see the status of each step after you start up and check where the error will be reported.

4. Possible error reports

Process:454 ExecStart=/etc/rc.local start (code=exited,status=1/FAILURE)

This error is probably due to the script file
if you just start, you must write the file path as an absolute path, otherwise an error will be reported.

error: (-2:Unspecified error) Can’t initialize GTK backend in function ‘cvInitSystem’

This error will be reported if the self startup program contains code with window operation such as OpenCV

The reason is caused by the following sentence

su pi -c “exec /home/pi/start.sh &”

If your command needs to run for a long time (such as an endless loop) or cannot exit after running, you must ensure that the “& amp;” symbol is added at the end of the command to make the command run in its background

If the code contains window interface operations similar to the following

cv2.namedWindow(‘Cap’)
cv2.imshow(‘Cap’, frame)

It will conflict with the background operation, so that the back end of GTK cannot be initialized and an error will be caused
the solution is to delete all the operations related to the interface and window, and the program can run well!