2020年1月14日星期二

Method to get all attributes of a Python object

In order to get all the attributes of a Python object, we only need to do the following:

dir(obj)

1only batches of spatial targets supported (non-empty 3D tensors) but got targets of size: :

I encountered the above problem when using Pytorch's CrossEntropy function.

E.g:
criterion = nn.CrossEntropyLoss()

loss = criterion(logit, target.long())
If logit.shape is torch.Size ([4, 31, 256, 256])  and target.shape is [4, 256, 256, 1], where 4 is the batchSize and 31 is the number of categories.

The error 1only batches of spatial targets supported (non-empty 3D tensors) but got targets of size:: will appear.

2020年1月5日星期日

FIFO over run error TCSPC (Pico Harp 300)

FIFO over run error in time-dependent single photon counter (model PicoHarp300) in continuous measurement mode

Reason: There are relevant instructions in the manual. In summary, there are too many photons and it is impossible to record in real time;

Solution: Turn down the laser power to reduce the number of photons per unit time.

Installation of scanning galvanometer GAS012 and GVS012

Step1: Remove the three hex screws on the side of GVS012

Step2: Align the three holes on the side of GAS012 with the three holes on the side of GVS012;

Step3: Screw the three hexagonal screws back on.

Step4: You can use the M4 / M6 screws to fix GAS012 to the optical tablet.

Image .save FileNotFoundError: [Errno 2] No such file or directory: '../Dataset/testResults/5.png'

Because it is .save, the reason is obviously not that there is no "../Dataset/testResults/5.png" file.

It is:

No ../Dataset/testResults/ directory

Example:


  1. This directory has not been created
  2. typo in the directory
  3. use Chinese or other characters.



After confirming that the directory is correct, the error is resolved.

ssh upload file to server

When there is a problem with the winsshfs mount file, you can directly use ssh to upload it, as follows:

scp ./1229.zip username@servername:~/

Python: divide a folder into small folders

Assume that there are 10,000 pictures in a large folder. This code is used to divide the 10,000 pictures into 9 subfolders according to the characteristics of the file name:

dir_sum   
    --dir1
    --dir2
    ...
    --dir9

RuntimeError: Given groups=1, weight of size [64, 3, , ], expected input[1, 4, , ] to have 3

This kind of problem that should be 3 channels and the result is 4 channels is generally due to the Image.open function.

Error statement:

img = Image.open(osp.join(dspth, image_path))

At this time, reading the picture is 4 channels, so an error will be reported.

It should be changed to:

 img = Image.open(osp.join(dspth, image_path)).convert('RGB')

Python: detect whether there is a problem with the pictures in a specified directory

When we use opencv to read pictures or use deep learning to read data sets, if there are problems with pictures, it will cause errors!

How to detect if all pictures in a folder are correct? The following code is summarized here.


Summary of SPAD photon detector usage

Here is a summary of the errors and experiences of using SPAD Detector (SPCM AQRH series):


1. Remove the black protective sleeve before use

This should be considered as common sense. But at the beginning, I didn't know it so that no data was obtained;


2. Note the enable termination high

The enable should be tied high to enable counting.

3. Pay attention to the focal length of the lens

The focal length of the front lens of the detector should be exactly equal to the distance of the lens from the detection hole, and fine-tuned to get the best detection structure.

4. Pay attention to height

The detector and laser must be aligned, otherwise the detection result will have an unexpectedly bad effect.

5. When buying, you should buy all the accessories

When purchasing, you should discuss the distribution requirements of the fixed components with the agent / producer in advance to facilitate subsequent installation and calibration.

Image Segmentation: Summary of Problems

1. Number of categories (label_nc / num_class)


Errors include:
RuntimeError: cuDNN error: CUDNN_STATUS_EXECUTION_FAILED

And other weird errors

Causes and solutions:
Imresize the label image

The default bilinear interpolation method almost inevitably generates new pixels, causing more classification problems and causing errors.

Solution: 
label = cv2.resize (label, (256,256), interpolation = cv2.INTER_NEAREST)

Use INTER_NEAREST interpolation.

Note: The method to view the number of labels: length (np.unique (label))

To be continued

Image segmentation / super pixel / parsing Github:

Face segmentation: https://github.com/zllrunning/face-parsing.PyTorch
Traditional method super pixel: https://github.com/mingyuliutw/EntropyRateSuperpixel
Generate real scene from segmentation graph: https://github.com/NVlabs/SPADE
Deeplab v3 + Pytorch version: https://github.com/jfzhang95/pytorch-deeplab-xception
CSAILVison Pytorch semantic segmentation: https://github.com/CSAILVision/semantic-segmentation-pytorch

Python: batch copy missing files with same name

Function: Batch copy missing files with the same name from other folders

# _*_ encoding:utf-8 _*_
import os
import sys
from shutil import copyfile

origin_A_train_path = './animeFaces/A/train/'
origin_A_test_path = './animeFaces/A/test/'

################################transfer training set #####################################
mode = 'train'
target_B_train_path = './data_superpixel_specifiedColor/B/'+mode+'/'
C_train_path = './data_superpixel_specifiedColor/C/'+mode+'/'
B_trainfile_name = os.listdir(target_B_train_path)
for image_index in range(len(B_trainfile_name)):
    image_name = B_trainfile_name[image_index]
    origin_image_file = origin_A_train_path + image_name
    if not os.path.exists(origin_image_file):
        print('test')
        origin_image_file = origin_A_test_path + image_name
    C_image_file = C_train_path + image_name
    copyfile(origin_image_file,C_image_file)


MATLAB: batch process pictures under specified path and save to another path


Function: Read all png files in a certain path, save them to another path by the original file name after batch processing



file_path =  './seeprettyface_models/';
img_path_list = dir(strcat(file_path,'*.png'));
dist_path = './chaomo/';


filePathTry = 'G:\Face\B_try\B_try';
filePathBtest = 'G:\Face\B_try\B\test';
filePathBtrain = 'G:\Face\B_try\B\train';
filePathBval = 'G:\Face\B_try\B\val';
filePathAtest = 'G:\Face\B_try\A\test';
filePathAtrain = 'G:\Face\B_try\A\train';
filePathAval = 'G:\Face\B_try\A\val';

h = waitbar(0,'Moving..., please wait');
% train
for im =1:length(img_path_list)
    fileName = img_path_list(im).name;
    filePath =  img_path_list(im).folder;
    fileImage = strcat(filePath,'\',fileName);
    distImage = strcat(dist_path,'\',fileName);
    image = imread(fileImage);
    image = imresize(image,[256,256]);
    imwrite(image,distImage);
    str = ['Moving image...',num2str(im*100/length(img_path_list)),'%'];
    waitbar(im/length(img_path_list),h,str)
end

MATLAB: train, test, val inedx number generation function


Function: Randomly draw 1% of integers between [1, N] into val; 1% into test; the rest into train

N = 10000;

A = [1:N]; 
A_temp = A;
val = [];
test = [];

% val
while length(val)<floor(N/100)
    temp = 1+floor(N.*rand(1));
    if ismember(temp,A_temp)
        val = [val, temp];
        A_temp = setdiff(A_temp,temp);
    end
end

% test
while length(test)<floor(N/100)
    temp = 1+floor(N.*rand(1));
    if ismember(temp,A_temp)
        test = [test, temp];
        A_temp = setdiff(A_temp,temp);
    end
end

% train
train = A_temp;

% sort()
test = sort(test);
val = sort(val);
train = sort(train);

Tensorboard:PermissionError: [Errno 13] Permission denied: '/tmp/.tensorboard-info/pid-20281.info'

Permission error when running TensorBoard:

PermissionError: [Errno 13] Permission denied: '/tmp/.tensorboard-info/pid-20281.info'


How to use RIGOL arbitrary function generator to generate arbitrary waveform

I bought a RIGOL function generator, but I don't know how to make it generate a custom irregular periodic signal. Here's how to generate it:


Server config file ./bashrc: reset and restore

When using a server, there may be unexpected situations such as the configuration file /.bashrc being suddenly emptied. This article documents the recovery steps for /.bashrc.