Tag Archives: artificial intelligence

[Solved] ParserError: NULL byte detected. This byte cannot be processed in Python‘s native csv library

ParserError: NULL byte detected. This byte cannot be processed in Python’s native csv library at the moment, so please pass in engine=’c’ instead



Error:

file_name = os.listdir(base_dir)[0]

col_list = [feature list]
col = col_list
#encoding
#data = pd.read_csv("D:\\test\\repo\\data.csv",sep = ',',encoding="GBK",usecols=range(len(col)))
    
data = pd.read_csv("D:\\test\\repo\\data.csv",sep = ',',encoding = 'unicode_escape', engine ='python')


#data = pd.read_csv("D:\\test\\repo\\data.csv",sep = ',',encoding = 'utf-8', engine ='python')

path = "D:\\test\\repo\\data.csv"

Solution:

engine =’c’

file_name = os.listdir(base_dir)[0]

#encoding
#data = pd.read_csv("D:\\test\\repo\\data.csv",sep = ',',encoding="GBK",usecols=range(len(col)))
    
data = pd.read_csv("D:\\test\\repo\\data.csv",sep = ',',encoding = 'unicode_escape', engine ='c')


#data = pd.read_csv("D:\\test\\repo\\data.csv",sep = ',',encoding = 'utf-8', engine ='python')

path = "D:\\test\\repo\\data.csv"

Full Error Messages:
—————————————————————————

Error                                     Traceback (most recent call last)
D:\anaconda\lib\site-packages\pandas\io\parsers.py in _next_iter_line(self, row_num)
2967             assert self.data is not None
-> 2968             return next(self.data)
2969         except csv.Error as e:
Error: line contains NULL byte
During handling of the above exception, another exception occurred:
ParserError                               Traceback (most recent call last)
<ipython-input-12-c5d0c651c50e> in <module>
85                    ]
86
---> 87     data = inference_process(data_dir)
88     #print(data.head())
89     f=open("break_model1.pkl",'rb')
<ipython-input-12-c5d0c651c50e> in inference_process(base_dir)
18     #encoding
19 #     data = pd.read_csv("D:\\test\\repo\\data.csv",sep = ',',encoding="GBK",usecols=range(len(col)))
---> 20     data = pd.read_csv("D:\\test\\repo\\data.csv",sep = ',',encoding = 'unicode_escape', engine ='python')
21 #     data = pd.read_csv("D:\\test\\repo\\data.csv",sep = ',',encoding = 'utf-8', engine ='python')
22
D:\anaconda\lib\site-packages\pandas\io\parsers.py in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options)
608     kwds.update(kwds_defaults)
609
--> 610     return _read(filepath_or_buffer, kwds)
611
612
D:\anaconda\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
460
461     # Create the parser.
--> 462     parser = TextFileReader(filepath_or_buffer, **kwds)
463
464     if chunksize or iterator:
D:\anaconda\lib\site-packages\pandas\io\parsers.py in __init__(self, f, engine, **kwds)
817             self.options["has_index_names"] = kwds["has_index_names"]
818
--> 819         self._engine = self._make_engine(self.engine)
820
821     def close(self):
D:\anaconda\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
1048             )
1049         # error: Too many arguments for "ParserBase"
-> 1050         return mapping[engine](self.f, **self.options)  # type: ignore[call-arg]
1051
1052     def _failover_to_python(self):
D:\anaconda\lib\site-packages\pandas\io\parsers.py in __init__(self, f, **kwds)
2308                 self.num_original_columns,
2309                 self.unnamed_cols,
-> 2310             ) = self._infer_columns()
2311         except (TypeError, ValueError):
2312             self.close()
D:\anaconda\lib\site-packages\pandas\io\parsers.py in _infer_columns(self)
2615             for level, hr in enumerate(header):
2616                 try:
-> 2617                     line = self._buffered_line()
2618
2619                     while self.line_pos <= hr:
D:\anaconda\lib\site-packages\pandas\io\parsers.py in _buffered_line(self)
2809             return self.buf[0]
2810         else:
-> 2811             return self._next_line()
2812
2813     def _check_for_bom(self, first_row):
D:\anaconda\lib\site-packages\pandas\io\parsers.py in _next_line(self)
2906
2907             while True:
-> 2908                 orig_line = self._next_iter_line(row_num=self.pos + 1)
2909                 self.pos += 1
2910
D:\anaconda\lib\site-packages\pandas\io\parsers.py in _next_iter_line(self, row_num)
2989                     msg += ". " + reason
2990
-> 2991                 self._alert_malformed(msg, row_num)
2992             return None
2993
D:\anaconda\lib\site-packages\pandas\io\parsers.py in _alert_malformed(self, msg, row_num)
2946         """
2947         if self.error_bad_lines:
-> 2948             raise ParserError(msg)
2949         elif self.warn_bad_lines:
2950             base = f"Skipping line {row_num}: "
ParserError: NULL byte detected. This byte cannot be processed in Python's native csv library at the moment, so please pass in engine='c' instea

[Solved] Runtimeerror during dcgan training: found dtype long but expected float

When using dcgan for network training, the following errors occur:

RuntimeError: Found dtype Long but expected Float

The code snippet for this error is as follows:

label = torch.full((b_size,), real_label, device=device)
        # Input the batch with positive samples into the discriminant network for forward computation and put the result into the variable output
        output = netD(real_cpu).view(-1)
    
        # Calculate the loss
        errD_real = criterion(output, label)

The reason is that the data type of the input output data and tag value into the loss function does not match the required data type. What is required is float type data, and what is passed in is long type data
therefore, we need to convert the incoming data to float type
the modified code is as follows:

label = torch.full((b_size,), real_label, device=device)
        # Input the batch with positive samples into the discriminant network for forward computation and put the result into the variable output
        output = netD(real_cpu).view(-1)
        # Convert the incoming data to float type
        output = output.to(torch.float32)
        label = label.to(torch.float32)
        # Calculate the loss
        errD_real = criterion(output, label)

Problem solved!

Error when downloading the built-in dataset of pytoch = urllib.error.urlerror: urlopen error [SSL: certificate_verify_failed]

Error reason:

This is an SSL certificate validation error. When an HTTPS site is requested, but the certificate validation error occurs, such an error will be reported.

Solution:

Just add the following two lines to the code to skip the certificate check and successfully access the web page.

# Global removal of certificate validation
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Error: could not find function … in R [How to Solve]

Error: could not find function … in R

Question:

solve:

Full error:


Question:

> mytest.ax(lable,prediction)
Error in mytest.ax(lable, prediction) :
could not find function “mytest.ax”

Solution:

First, is the function name written correctly?R language function names are case sensitive.

Second, is the package containing the function installed?install.packages(“package_name”)

Third,

require(package_name)

library(package)

Require (package_name) (and check its return value) or library (package) (this should be done every time you start a new R session)

Fourth, are you using an old r version that does not yet exist?Or the version of R package; Or after the version is updated, some functions are removed from the original package;

Fifth, functions are added and removed over time, and the referenced code may expect an updated or older version than the package you installed. Or it’s too new. Cran doesn’t contain the latest version;

Full error:

> mytest.ax(lable,prediction)
Error in mytest.ax(lable, prediction) :
could not find function "mytest.ax"

RuntimeError: Found dtype Double but expected Float”

RuntimeError: Found dtype Double but expected Float”

I made a mistake in finding the loss function,

resolvent:

target.float()

a=np.array([[1,2],[3,4]])
b=np.array([[2,3],[4,4]])

loss_fn = torch.nn.MSELoss(reduce=True, size_average=True)

input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))

loss = loss_fn(input.float(), target.float())

print(loss)

Pytorch torch.cuda.FloatTensor Error: RuntimeError: one of the variables needed for gradient computation has…

pytorch 1.9 Error:
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [4, 512, 16, 16]], which is output 0 of ConstantPadNdBackward, is at version 1; expected version 0 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True). #23
At first I thought it was the input z = torch.randn(batch_size, 128,1,1).to(device).
Solution:
pip install torch == 1.4 torchvision = 0.05

Resolve the error raise importerror, str (MSG) + ‘, please install the python TK package’ (valid for personal testing)

Solve the following similar error reports:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 42, in <module>
    raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: /usr/lib/libtk8.5.so.0: invalid ELF header, please install the python-tk package

terms of settlement:

It appears that the library is corrupted
try sudo apt get remove Python TK ,
then sudo apt get clean download the package again,
sudo apt get install Python TK and then try importing again
this problem is resolved.

Another possibility is that you somehow messed up your apt/sources. List, and you installed a library for the wrong platform.

Reference link:
https://stackoverflow.com/questions/11043844/python-tk-package-not-recognized-in-python-2-7-3

Opencv453 drawing rectangle function error reporting solution

# draw gt
cv2.rectangle(img, (gt[0], gt[1]), (gt[2], gt[3]), (0,255,0), 1)

The following error occurred while running:

The rectangle function in opencv453 is incompatible with floating-point data  

terms of settlement:

It is OK to convert the two coordinate data types in the rectangle function to int

cv2.rectangle(img, (int(gt[0]), int(gt[1])), (int(gt[2]), int(gt[3])),(0,255,0), 1)

[Solved] Opencv Compile Error: (CMake Error: The following variables are used in this project, but they are set to not)

report errors

On Jetson NX, an error occurred while compiling opencv4.1.1. The error is as follows

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_cublas_LIBRARY (ADVANCED)
    linked by target "opencv_cudev" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudev
    linked by target "opencv_test_cudev" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudev/test
    linked by target "opencv_test_core" in directory /opt/opencv4/opencv-4.1.1/modules/core
    linked by target "opencv_perf_core" in directory /opt/opencv4/opencv-4.1.1/modules/core
    linked by target "opencv_core" in directory /opt/opencv4/opencv-4.1.1/modules/core
    linked by target "opencv_test_cudaarithm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaarithm
    linked by target "opencv_cudaarithm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaarithm
    linked by target "opencv_cudaarithm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaarithm
    linked by target "opencv_perf_cudaarithm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaarithm
    linked by target "opencv_flann" in directory /opt/opencv4/opencv-4.1.1/modules/flann
    linked by target "opencv_test_flann" in directory /opt/opencv4/opencv-4.1.1/modules/flann
    linked by target "opencv_perf_imgproc" in directory /opt/opencv4/opencv-4.1.1/modules/imgproc
    linked by target "opencv_test_imgproc" in directory /opt/opencv4/opencv-4.1.1/modules/imgproc
    linked by target "opencv_imgproc" in directory /opt/opencv4/opencv-4.1.1/modules/imgproc
    linked by target "opencv_test_ml" in directory /opt/opencv4/opencv-4.1.1/modules/ml
    linked by target "opencv_ml" in directory /opt/opencv4/opencv-4.1.1/modules/ml
    linked by target "opencv_test_phase_unwrapping" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/phase_unwrapping
    linked by target "opencv_phase_unwrapping" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/phase_unwrapping
    linked by target "opencv_plot" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/plot
    linked by target "opencv_test_quality" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/quality
    linked by target "opencv_quality" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/quality
    linked by target "opencv_test_reg" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/reg
    linked by target "opencv_reg" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/reg
    linked by target "opencv_perf_reg" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/reg
    linked by target "opencv_surface_matching" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/surface_matching
    linked by target "opencv_test_cudafilters" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudafilters
    linked by target "opencv_perf_cudafilters" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudafilters
    linked by target "opencv_cudafilters" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudafilters
    linked by target "opencv_test_cudaimgproc" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaimgproc
    linked by target "opencv_cudaimgproc" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaimgproc
    linked by target "opencv_perf_cudaimgproc" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaimgproc
    linked by target "opencv_test_cudawarping" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudawarping
    linked by target "opencv_cudawarping" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudawarping
    linked by target "opencv_perf_cudawarping" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudawarping
    linked by target "opencv_dnn" in directory /opt/opencv4/opencv-4.1.1/modules/dnn
    linked by target "opencv_perf_dnn" in directory /opt/opencv4/opencv-4.1.1/modules/dnn
    linked by target "opencv_test_dnn" in directory /opt/opencv4/opencv-4.1.1/modules/dnn
    linked by target "opencv_features2d" in directory /opt/opencv4/opencv-4.1.1/modules/features2d
    linked by target "opencv_perf_features2d" in directory /opt/opencv4/opencv-4.1.1/modules/features2d
    linked by target "opencv_test_features2d" in directory /opt/opencv4/opencv-4.1.1/modules/features2d
    linked by target "opencv_test_fuzzy" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/fuzzy
    linked by target "opencv_fuzzy" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/fuzzy
    linked by target "opencv_hfs" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/hfs
    linked by target "opencv_test_img_hash" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/img_hash
    linked by target "opencv_img_hash" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/img_hash
    linked by target "opencv_imgcodecs" in directory /opt/opencv4/opencv-4.1.1/modules/imgcodecs
    linked by target "opencv_perf_imgcodecs" in directory /opt/opencv4/opencv-4.1.1/modules/imgcodecs
    linked by target "opencv_test_imgcodecs" in directory /opt/opencv4/opencv-4.1.1/modules/imgcodecs
    linked by target "opencv_test_line_descriptor" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/line_descriptor
    linked by target "opencv_perf_line_descriptor" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/line_descriptor
    linked by target "opencv_line_descriptor" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/line_descriptor
    linked by target "opencv_test_photo" in directory /opt/opencv4/opencv-4.1.1/modules/photo
    linked by target "opencv_photo" in directory /opt/opencv4/opencv-4.1.1/modules/photo
    linked by target "opencv_perf_photo" in directory /opt/opencv4/opencv-4.1.1/modules/photo
    linked by target "opencv_test_saliency" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/saliency
    linked by target "opencv_saliency" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/saliency
    linked by target "opencv_test_videoio" in directory /opt/opencv4/opencv-4.1.1/modules/videoio
    linked by target "opencv_videoio" in directory /opt/opencv4/opencv-4.1.1/modules/videoio
    linked by target "opencv_perf_videoio" in directory /opt/opencv4/opencv-4.1.1/modules/videoio
    linked by target "opencv_test_xphoto" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xphoto
    linked by target "opencv_perf_xphoto" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xphoto
    linked by target "opencv_xphoto" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xphoto
    linked by target "opencv_calib3d" in directory /opt/opencv4/opencv-4.1.1/modules/calib3d
    linked by target "opencv_perf_calib3d" in directory /opt/opencv4/opencv-4.1.1/modules/calib3d
    linked by target "opencv_test_calib3d" in directory /opt/opencv4/opencv-4.1.1/modules/calib3d
    linked by target "opencv_test_cudacodec" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudacodec
    linked by target "opencv_cudacodec" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudacodec
    linked by target "opencv_perf_cudacodec" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudacodec
    linked by target "opencv_test_cudafeatures2d" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudafeatures2d
    linked by target "opencv_cudafeatures2d" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudafeatures2d
    linked by target "opencv_perf_cudafeatures2d" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudafeatures2d
    linked by target "opencv_test_cudastereo" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudastereo
    linked by target "opencv_cudastereo" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudastereo
    linked by target "opencv_perf_cudastereo" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudastereo
    linked by target "opencv_test_highgui" in directory /opt/opencv4/opencv-4.1.1/modules/highgui
    linked by target "opencv_highgui" in directory /opt/opencv4/opencv-4.1.1/modules/highgui
    linked by target "opencv_test_objdetect" in directory /opt/opencv4/opencv-4.1.1/modules/objdetect
    linked by target "opencv_objdetect" in directory /opt/opencv4/opencv-4.1.1/modules/objdetect
    linked by target "opencv_perf_objdetect" in directory /opt/opencv4/opencv-4.1.1/modules/objdetect
    linked by target "opencv_rgbd" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/rgbd
    linked by target "opencv_test_rgbd" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/rgbd
    linked by target "opencv_test_shape" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/shape
    linked by target "opencv_shape" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/shape
    linked by target "opencv_test_structured_light" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/structured_light
    linked by target "opencv_structured_light" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/structured_light
    linked by target "opencv_text" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/text
    linked by target "opencv_test_text" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/text
    linked by target "opencv_ts" in directory /opt/opencv4/opencv-4.1.1/modules/ts
    linked by target "opencv_video" in directory /opt/opencv4/opencv-4.1.1/modules/video
    linked by target "opencv_perf_video" in directory /opt/opencv4/opencv-4.1.1/modules/video
    linked by target "opencv_test_video" in directory /opt/opencv4/opencv-4.1.1/modules/video
    linked by target "opencv_xfeatures2d" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xfeatures2d
    linked by target "opencv_perf_xfeatures2d" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xfeatures2d
    linked by target "opencv_test_xfeatures2d" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xfeatures2d
    linked by target "opencv_perf_ximgproc" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/ximgproc
    linked by target "opencv_ximgproc" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/ximgproc
    linked by target "opencv_test_ximgproc" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/ximgproc
    linked by target "opencv_xobjdetect" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/xobjdetect
    linked by target "opencv_test_aruco" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/aruco
    linked by target "opencv_aruco" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/aruco
    linked by target "opencv_bgsegm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/bgsegm
    linked by target "opencv_test_bgsegm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/bgsegm
    linked by target "opencv_test_bioinspired" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/bioinspired
    linked by target "opencv_perf_bioinspired" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/bioinspired
    linked by target "opencv_bioinspired" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/bioinspired
    linked by target "opencv_ccalib" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/ccalib
    linked by target "opencv_test_cudabgsegm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudabgsegm
    linked by target "opencv_cudabgsegm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudabgsegm
    linked by target "opencv_perf_cudabgsegm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudabgsegm
    linked by target "opencv_test_cudalegacy" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudalegacy
    linked by target "opencv_cudalegacy" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudalegacy
    linked by target "opencv_perf_cudalegacy" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudalegacy
    linked by target "opencv_test_cudaobjdetect" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaobjdetect
    linked by target "opencv_perf_cudaobjdetect" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaobjdetect
    linked by target "opencv_cudaobjdetect" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaobjdetect
    linked by target "opencv_datasets" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/datasets
    linked by target "opencv_dnn_objdetect" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/dnn_objdetect
    linked by target "opencv_dpm" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/dpm
    linked by target "opencv_test_face" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/face
    linked by target "opencv_face" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/face
    linked by target "opencv_test_optflow" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/optflow
    linked by target "opencv_optflow" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/optflow
    linked by target "opencv_perf_optflow" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/optflow
    linked by target "opencv_stitching" in directory /opt/opencv4/opencv-4.1.1/modules/stitching
    linked by target "opencv_test_tracking" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/tracking
    linked by target "opencv_tracking" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/tracking
    linked by target "opencv_perf_tracking" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/tracking
    linked by target "opencv_cudaoptflow" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaoptflow
    linked by target "opencv_perf_cudaoptflow" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaoptflow
    linked by target "opencv_test_cudaoptflow" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/cudaoptflow
    linked by target "opencv_test_stereo" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/stereo
    linked by target "opencv_stereo" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/stereo
    linked by target "opencv_perf_stereo" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/stereo
    linked by target "opencv_test_superres" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/superres
    linked by target "opencv_superres" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/superres
    linked by target "opencv_perf_superres" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/superres
    linked by target "opencv_test_videostab" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/videostab
    linked by target "opencv_videostab" in directory /opt/opencv4/opencv_contrib-4.1.1/modules/videostab
    linked by target "opencv_annotation" in directory /opt/opencv4/opencv-4.1.1/apps/annotation
    linked by target "opencv_visualisation" in directory /opt/opencv4/opencv-4.1.1/apps/visualisation
    linked by target "opencv_interactive-calibration" in directory /opt/opencv4/opencv-4.1.1/apps/interactive-calibration
    linked by target "opencv_version" in directory /opt/opencv4/opencv-4.1.1/apps/version

-- Configuring incomplete, errors occurred!
See also "/opt/opencv4/opencv-4.1.1/build/CMakeFiles/CMakeOutput.log".
See also "/opt/opencv4/opencv-4.1.1/build/CMakeFiles/CMakeError.log".

Solution

This is due to the lack of CUDA files.

Since I am CUDA 10.2, I choose cuda-toolkit-10-2 and the corresponding cuda-toolkit-x-x according to CUDA version. We install it directly, and the missing files will be downloaded and installed automatically,

sudo apt-get update
sudo apt-get install cuda-toolkit-10-2

After installation, recompile opnecv.

RuntimeError: stack expects each tensor to be equal size [How to Solve]

When debugging the code of densenet for classification task, the following errors are encountered in the process of image preprocessing:
runtimeerror: stack expectations each tensor to be equal size, but got [640, 640] at entry 0 and [560, 560] at entry 2
it means that the size of the loaded sheets is inconsistent
after searching, it is found that there should be a problem in the preprocessing process when I load the image
the following is the instantiation part of training data preprocessing.

train_transform = Compose(
        [
            LoadImaged(keys=keys),
            AddChanneld(keys=keys),
            CropForegroundd(keys=keys[:-1], source_key="tumor"),
            ScaleIntensityd(keys=keys[:-1]),
            # # Orientationd(keys=keys[:-1], axcodes="RAI"),
            Resized(keys=keys[:-1], spatial_size=(64, 64), mode='bilinear'),
            ConcatItemsd(keys=keys[:-1], name="image"),
            RandGaussianNoised(keys=["image"], std=0.01, prob=0.15),
            RandFlipd(keys=["image"], prob=0.5),  # , spatial_axis=[0, 1]
            RandAffined(keys=["image"], mode='bilinear', prob=1.0, spatial_size=[64, 64],    # The 3 here is because we don't know what the size of the three modal images will be after stitching, so we first use
                        rotate_range=(0, 0, np.pi/15), scale_range=(0.1, 0.1)),
            ToTensord(keys=keys),
        ]

    )

My keys are [“t2_img”, “dwi_img”, “adc_img”, “tumor”]
the error shows that the loaded tensor has dimensions [640, 640] and [560, 560], which are the dimensions of my original image, which indicates that there may be a problem in my clipping step or resize step. Finally, after screening, it is found that there is a problem in my resize step. In the resize step, I selected keys = keys [: – 1], that is, it does not contain “tumor”. Therefore, when resizing, my tumor image will still maintain the size of the original image, and the data contained in this dictionary will still be a whole when loaded, The dimensions of each dimension of the whole will automatically expand to the largest of the corresponding dimensions of all objects, so the data I loaded will still be the size of the original drawing. Make the following corrections:

 train_transform = Compose(
        [
            LoadImaged(keys=keys),
            AddChanneld(keys=keys),
            CropForegroundd(keys=keys[:-1], source_key="tumor"),
            ScaleIntensityd(keys=keys[:-1]),
            # # Orientationd(keys=keys[:-1], axcodes="RAI"),
            Resized(keys=keys, spatial_size=(64, 64), mode='bilinear'),  # remove [:-1]
            ConcatItemsd(keys=keys[:-1], name="image"),
            RandGaussianNoised(keys=["image"], std=0.01, prob=0.15),
            RandFlipd(keys=["image"], prob=0.5),  # , spatial_axis=[0, 1]
            RandAffined(keys=["image"], mode='bilinear', prob=1.0, spatial_size=[64, 64],    # The 3 here is because we don't know what the size of the three modal images will be after stitching, so we first use
                        rotate_range=(0, 0, np.pi/15), scale_range=(0.1, 0.1)),
            ToTensord(keys=keys),
        ]

    )

Run successfully!

Error in plot.new() : figure margins too large

Error in plot.new() : figure margins too large

Full error:


#Question

Fit the regression model and calculate the dfbetas value of each sample and the optimal dfbetas threshold. Finally, visualize the impact of each sample on each predictive variable;

#fit a regression model
model <- lm(mpg~disp+hp, data=mtcars)

#view model summary
summary(model)

#calculate DFBETAS for each observation in the model
dfbetas <- as.data.frame(dfbetas(model))

#display DFBETAS for each observation
dfbetas

#find number of observations
n <- nrow(mtcars)

#calculate DFBETAS threshold value
thresh <- 2/sqrt(n)

thresh

#specify 2 rows and 1 column in plotting region

#dev.off()
#par(mar = c(1, 1, 1, 1))

par(mfrow=c(2,1))

#plot DFBETAS for disp with threshold lines
plot(dfbetas$disp, type='h')
abline(h = thresh, lty = 2)
abline(h = -thresh, lty = 2)

#plot DFBETAS for hp with threshold lines 
plot(dfbetas$hp, type='h')
abline(h = thresh, lty = 2)
abline(h = -thresh, lty = 2)

#Solution
par(mar = c(1, 1, 1, 1))

#fit a regression model
model <- lm(mpg~disp+hp, data=mtcars)

#view model summary
summary(model)

#calculate DFBETAS for each observation in the model
dfbetas <- as.data.frame(dfbetas(model))

#display DFBETAS for each observation
dfbetas

#find number of observations
n <- nrow(mtcars)

#calculate DFBETAS threshold value
thresh <- 2/sqrt(n)

thresh

#specify 2 rows and 1 column in plotting region

#dev.off()
par(mar = c(1, 1, 1, 1))

par(mfrow=c(2,1))

#plot DFBETAS for disp with threshold lines
plot(dfbetas$disp, type='h')
abline(h = thresh, lty = 2)
abline(h = -thresh, lty = 2)

#plot DFBETAS for hp with threshold lines 
plot(dfbetas$hp, type='h')
abline(h = thresh, lty = 2)
abline(h = -thresh, lty = 2)


Full Error Message:
> par(mfrow=c(2,1))
>
> #plot DFBETAS for disp with threshold lines
> plot(dfbetas$disp, type=’h’)
Error in plot.new() : figure margins too large
> abline(h = thresh, lty = 2)
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, …) :
plot.new has not been called yet
> abline(h = -thresh, lty = 2)
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, …) :
plot.new has not been called yet
>
> #plot DFBETAS for hp with threshold lines
> plot(dfbetas$hp, type=’h’)
Error in plot.new() : figure margins too large
> abline(h = thresh, lty = 2)
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, …) :
plot.new has not been called yet
> abline(h = -thresh, lty = 2)
Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, …) :
plot.new has not been called yet

Error in *** : subscript out of bounds [How to Solve]

Error in *** : subscript out of bounds

Full error:


Question:

The data is out of bounds. Except for others, who knows where it is? Do you ask memory? Who do you ask?

#make this example reproducible
set.seed(0)

#create matrix with 10 rows and 3 columns
x = matrix(data = sample.int(100, 30), nrow = 10, ncol = 3)

#print matrix
print(x)

#attempt to display 11th row of matrix
x[11, ]

#attempt to display 4th column of matrix
x[, 4]

#attempt to display value in 11th row and 4th column
x[11, 4]

Solution:

#

#display number of rows and columns in matrix
dim(x)

#

#display 10th row of matrix
x[10, ]

#display number of columns in matrix
ncol(x)

#display 3rd column of matrix
x[, 3]

#display value in 10th row and 3rd column of matrix
x[10, 3]

Full error Messages:
>
> #attempt to display 11th row of matrix
> x[11, ]
Error in x[11, ] : subscript out of bounds
>
> #attempt to display 4th column of matrix
> x[, 4]
Error in x[, 4] : subscript out of bounds
>
> #attempt to display value in 11th row and 4th column
> x[11, 4]
Error in x[11, 4] : subscript out of bounds
>