1/25/2023

RuntimeError: CUDA error: CUBLAS_STATUS_INVALID_VALUE when calling `cublasSgemm( handle, opa, opb, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)`

 

I was suffering above (title) error during few hours.

The reason is wrong cuda version installed with pytorch.

My cuda version is 11.6, but install version is 11.7.


So I print it -> "torch.__version__"

It returend -> "1.13.1+cu117"


You can check your cuda version using this command

> nvidia-smi


so, remove all torch, torchvision packaged

> pip uninstall torch torchvision

and install again

ex)

pip3 install torch torchvision torchaudio --extra-index-url \https://download.pytorch.org/whl/cu116


Then it works well.


Thank you.

๐Ÿ™‡๐Ÿป‍♂️

1/23/2023

PIL image to tensor

 refer to code

key is "transforms.PILToTensor"

..

import torch
from PIL import Image
import torchvision.transforms as transforms
pil_image = Image.open('input.jpg')
transform = transforms.Compose([
transforms.PILToTensor()
])
tensor_img = transform(pil_image)
print(tensor_img)

..


Thx. ๐Ÿ™‡๐Ÿป‍♂️

1/19/2023

opencv c++ gpumat mat(cpu) memory share

refer to code:

..

size_t frameByteSize = initMat.step[0] * initMat.rows;

#ifndef USE_UNIFIED_MEM
    /* Pinned memory. No cache */
    std::cout << "Using pinned memory" << std::endl;
    void* device_ptr, * host_ptr;
    cudaSetDeviceFlags(cudaDeviceMapHost);
    cudaHostAlloc((void**)&host_ptr, frameByteSize, cudaHostAllocMapped);
    cudaHostGetDevicePointer((void**)&device_ptr, (void*)host_ptr, 0);
    cv::Mat frame_out(height, width, CV_8UC3, host_ptr);
    cv::cuda::GpuMat d_frame_out(height, width, CV_8UC3, device_ptr);
#else
    /* Unified memory */
    std::cout << "Using unified memory" << std::endl;
    void* unified_ptr;
    cudaMallocManaged(&unified_ptr, frameByteSize);
    cv::Mat frame_out(height, width, CV_8UC3, unified_ptr);
    cv::cuda::GpuMat d_frame_out(height, width, CV_8UC3, unified_ptr);
#endif

..


another example

..

void* m_device_ptr = NULL;
void* m_host_ptr = NULL;

//memory share frame -> cuda_frame
cudaSetDeviceFlags(cudaDeviceMapHost);
size_t frameByteSize = initMat.step[0] * initMat.rows;
cudaHostAlloc((void**)&m_host_ptr, frameByteSize, cudaHostAllocMapped);
cudaHostGetDevicePointer((void**)&m_device_ptr, (void*)m_host_ptr, 0);
cv::Mat m_frame = cv::Mat(initMat.rows, initMat.cols, CV_8UC3, m_host_ptr);
cv::cuda::GpuMat m_cuda_frame = cv::cuda::GpuMat(initMat.rows, initMat.cols, CV_8UC3, m_device_ptr);

//initiation
iframes.copyTo(m_frame);

..



1/12/2023

Opencv Mat <-> UMat , convert Mat to UMat, UMat to Mat

Mat to UMat 

c++

UMat umat;
mat.copyTo(umat);

Python

UMat umat = mat.getUMat( flag );


UMat to Mat

C++

Mat mat = umat.getMat( flag );

Python

mat = cv2.UMat.get(umat)

1/11/2023

How to call module written with argparse in iPython notebook

 


Add this two line above "argparse.ArgumentParser()" line

ex)

..

##add sys code ##
import sys
sys.argv = ['']

##origin code##
import argparse
parser = argparse.ArgumentParser()
args = parser.parse_args()

..


Thx. ๐Ÿ™‡๐Ÿป‍♂️

www.marearts.com

1/10/2023

IProgress not found. Please update jupyter and ipywidgets.

 

IProgress not found. Please update jupyter and ipywidgets.


..

pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension

..


thx


idx2label, label2idx python code

refer to code:

...

labels = ['B-answer', 'I-answer', 'B-header', 'I-header', 'B-question', 'I-question', 'B-other', 'I-other']
idx2label = {v: k for v, k in enumerate(labels)}
label2idx = {k: v for v, k in enumerate(labels)}
print(f'{idx2label=}')
print(f'{label2idx=}')

...


idx2label={0: 'B-answer', 1: 'I-answer', 2: 'B-header', 3: 'I-header', 4: 'B-question', 5: 'I-question', 6: 'B-other', 7: 'I-other'}
label2idx={'B-answer': 0, 'I-answer': 1, 'B-header': 2, 'I-header': 3, 'B-question': 4, 'I-question': 5, 'B-other': 6, 'I-other': 7}


Thx!

SSLCertVerificationError when downloading pytorch model or datasets via torchvision

 

I tried to download resnet101 model via torchvision model 

ex) torchvision.models.resnet101(pretrained=True)

But it has such a error

---------------------------------------------------------------------------
SSLCertVerificationError                  Traceback (most recent call last)
F........


This line would solve this issue :

..

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

..


Thank you.


www.marearts.com