Thursday, 25 May 2023

How to attach a docker container in visual studio code? CMake debug?

  1. Install the "C++", "Dev Containers", "CMake", "CMake Tools" under marketplace
  2. After that, crtl + shift + p and search "attach"
  3. Then, you can create a root folder, ".vscode" and create a new file named as "settings.json" as below:-

{

    "cmake.debugConfig": {

      "args": [

        "arg1",

        "arg2",

        "--flag",

        "value"

      ]

    }

  }

  

    4. Finally, crtl + shift + p -> CMake Debug

Wednesday, 24 May 2023

error: (-217:Gpu API call) no kernel image is available for execution on the device in function 'call'

Error:

terminate called after throwing an instance of 'cv::Exception'

what(): OpenCV(4.4.0) /data/opencv_contrib-4.4.0/modules/cudev/include/opencv2/cudev/grid/detail/transform.hpp:312: error: (-217:Gpu API call) no kernel image is available for execution on the device in function 'call' /data/client/scripts/run1.sh: line 1: 192338 Aborted (core dumped) /main 1 rtsp://localhost/test1


Solution:
Check opencv compilation -DCUDA_ARCH_BIN="7.5" or "8.6" or "8.9"
  • 7.5 is for 2080ti
  • 8.6 is for 3090
  • 8.9 is for 4090

Thursday, 18 May 2023

How to use cnpy to cross the value between cpp and python?

CPP Version

#include"cnpy.h"

#include "opencv2/core.hpp"

#include "opencv2/imgproc.hpp"

#include "opencv2/highgui.hpp"


using namespace cv;


int main()

{

    Mat img(100, 100, CV_32FC3);

    randu(img, Scalar(0, 0, 0), Scalar(255, 255, 255));

    std::cout << img << std::endl;

    img = img/255.0;

    std::cout << img << std::endl;

    float* tmp = (float*)img.data;

    cnpy::npy_save("img.npy", tmp, {100,100,3},"w");

    // cv::imwrite("img1.jpg", img);

}


Python Version

import numpy as np

import cv2


temp = np.load("img.npy")

print(temp)

# cv2.imwrite("img2.jpg", temp)


How to rsync from one machine to another machine?

 sshpass -p "PASSWORD" rsync -avzh LOCAL_PATH -e 'ssh -p PORT' USERNAME@IP_ADDRESS:REMOTE_PATH

Wednesday, 17 May 2023

How to listen or telnet between 2 ubuntu PCs, to verify firewall in ubuntu pc?

one way is to use telnet in a ubuntu pc

telnet <IP address> <Port>

telnet 44.55.66.77 9090


another way is to use nc for listening to a port

in the host pc: nc -l 9090

in the remote pc: nc 44.55.66.77 9090

then, type anything on remote pc, you should see it in host pc


If you want to check it from windows, open PowerShell:-

Test-NetConnection -ComputerName host -Port port

Test-NetConnection -ComputerName 192.168.0.1 -Port 80

Tuesday, 9 May 2023

How to share internet between ubuntu pc using a usb wifi dongle?

pcA: ubuntu with usb dongle, with internet

pcB: ubuntu without usb dongle, no internet


step1: check the IP address of pcA if change the IPv4 Method to "Shared to other computers". Prior to this, pcA should have a default IP address and we named it as pcAip1.

Please take note that do not change any setting on "USB Ethernet" because it is an internet connection.

You should change the setting only on "PCI Ethernet".

Open setting of "PCI Ethernet", select IPv4, select "Shared to other computers" under IPv4 Method.

Once it is done, just click Apply.

Then, open terminal and type "nmcli dev show eth0" where eth0 is the network interface name of "PCI Ethernet", sometime it is named as "enp8s0", "enp3s0", etc.

You should get IP address of pcA under "Shared to other computers" condition and we named it as pcAip2:-

IP4.ADDRESS[1]:                         10.42.0.1/24

You will see a different IP address if you change the "Shared to other computers" to Automatic or Manual, which is pcAip1. Write down the pcAip2.

Change it back to manual IP addresss so that you can connect to pcB using original IP.


step2: ssh and login to pcB using default IP address or pcBip1, type "sudo nmtui", edit connection of wired connection

change the setting from before to after as following:-

before, we have pcBip1: 10.201.56.19


after, we have pcBip2: 10.42.0.2


where you should define a temporary IP address of pcB which is 10.42.0.2/24, Gateway you should put pcAip2 which is 10.42.0.1 without 24, DNS servers also the same.

Once it is done, you can reboot pcB.

step3: now from pcA, change again the IPv4 method from manual to "Shared to other computers".

Open terminal, you can try to ssh login pcB using pcBip2 address. Once you login, you can try to ping www.google.com. If you able to receive a reply from Google, then congrats. If not, something wrong with your setting, try again.


step4: now in pcB, you have done your business with internet connection, you want to switch it back to original setting which is from pcBip2 to pcBip1. You can just reverse the setting in step2. Then, you can reboot pcB.


step5: back to pcA, you can restore the PCI Ethernet setting back to pcAip1. You should able to connect pcBip1 as usual, but pcB should not have any internet now

Monday, 1 May 2023

How to check pytorch installation error?

import torch

torch.backends.cuda.matmul.allow_tf32 = True

torch.backends.cudnn.benchmark = True

torch.backends.cudnn.deterministic = False

torch.backends.cudnn.allow_tf32 = True

data = torch.randn([1, 512, 120, 67], dtype=torch.float, device='cuda', requires_grad=True)

net = torch.nn.Conv2d(512, 512, kernel_size=[3, 3], padding=[1, 1], stride=[1, 1], dilation=[1, 1], groups=1)

net = net.cuda().float()

out = net(data)

out.backward(torch.randn_like(out))

torch.cuda.synchronize()