When testing the trained network, python finds the above problems and adds them after loading the network model.eval (), the problem is solved.
model = nn.DataParallel(model).cpu()
model.load_state_dict(torch.load(path, map_location=torch.device('cpu')), False)
model.eval()
There are three things to note about this code snippet
nn.DataParallel(model)
If you add this function to the training network, you also need to add this function to the training network
model.load_state_dict(torch.load(path, map_location=torch.device('cpu')), False)
If the network framework is not saved when the network is saved and only parameters are available, the network can be loaded by the above method. If the GPU is used when the network is trained and the parameter map is added on the CPU when the network is used_ location= torch.device (‘cpu’)
model.eval()
The third is the problem of the topic. After loading the network, add the above function to solve the problem
Read More:
- raise ValueError(‘Expected input batch_size ({}) to match target batch_size ({}).‘
- Copying a param with shape torch. Size ([262, 2048]), parameter size does not match
- RuntimeError: Expected hidden[0] size (x, x, x), got(x, x, x)
- ValueError: not enough values to unpack (expected 6, got 1)
- ValueError: not enough values to unpack (expected 2, got 0)
- Python3-ValueError:not enough values to unpack (expected 2, got 0)
- RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the
- Error occurred when Python called cv2.findcontours: valueerror: not enough values to unpack (expected 3, got 2)
- [solved] error: valueerror: expected 2D array, got scalar array instead
- To solve the problem of increasing video memory when training network (torch)
- error C2057: expected constant expression (Can the size of an array in C language be defined when the program is running?)
- Pandas read_ Error in json() valueerror: training data
- (26)RuntimeError: Error(s) in loading state_dict for YoloBody:size mismatch for yolo_head3.1.weight
- Android Error: Consumer closed input channel or an error occurred. events=0x9
- Error in data training: valueerror: unknown label type: ‘continuous‘
- Build your own resnet18 network and load torch vision’s own weight
- ValueError: num_samples should be a positive integer value, but got num_samp=0