add input and output in resnet50 demo
| After Width: | Height: | Size: 112 KiB | 
| After Width: | Height: | Size: 116 KiB | 
| After Width: | Height: | Size: 133 KiB | 
| After Width: | Height: | Size: 58 KiB | 
| After Width: | Height: | Size: 97 KiB | 
| After Width: | Height: | Size: 59 KiB | 
| After Width: | Height: | Size: 170 KiB | 
| After Width: | Height: | Size: 59 KiB | 
| After Width: | Height: | Size: 170 KiB | 
| After Width: | Height: | Size: 206 KiB | 
|  | @ -235,3 +235,23 @@ int RN50_layer4__modules_2_bn3_weight[]={23414720,23416767,}; | |||
| int RN50_layer4__modules_2_bn3_bias[]={23416768,23418815,}; | ||||
| int RN50_fc_weight[]={23418816,25466815,}; | ||||
| int RN50_fc_bias[]={25466816,25467815,}; | ||||
| int input_0[]={25467816,25618343,}; | ||||
| int output_0[]={25618344,25619343,}; | ||||
| int input_1[]={25619344,25769871,}; | ||||
| int output_1[]={25769872,25770871,}; | ||||
| int input_2[]={25770872,25921399,}; | ||||
| int output_2[]={25921400,25922399,}; | ||||
| int input_3[]={25922400,26072927,}; | ||||
| int output_3[]={26072928,26073927,}; | ||||
| int input_4[]={26073928,26224455,}; | ||||
| int output_4[]={26224456,26225455,}; | ||||
| int input_5[]={26225456,26375983,}; | ||||
| int output_5[]={26375984,26376983,}; | ||||
| int input_6[]={26376984,26527511,}; | ||||
| int output_6[]={26527512,26528511,}; | ||||
| int input_7[]={26528512,26679039,}; | ||||
| int output_7[]={26679040,26680039,}; | ||||
| int input_8[]={26680040,26830567,}; | ||||
| int output_8[]={26830568,26831567,}; | ||||
| int input_9[]={26831568,26982095,}; | ||||
| int output_9[]={26982096,26983095,}; | ||||
|  |  | |||
|  | @ -14,11 +14,14 @@ import numpy as np | |||
| import struct | ||||
| from struct import Struct | ||||
| 
 | ||||
| 
 | ||||
| CurrentPath = os.path.split(os.path.realpath(__file__))[0]+"/" | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| resnet50 = models.resnet50(pretrained=True) | ||||
| torch.save(resnet50, CurrentPath+'params.pth') | ||||
| # torch.save(resnet50, CurrentPath+'params.pth') | ||||
| resnet50 = torch.load(CurrentPath+'params.pth') | ||||
| print("===========================") | ||||
| print("===========================") | ||||
|  | @ -29,20 +32,6 @@ print("===========================") | |||
| print("===========================") | ||||
| 
 | ||||
| 
 | ||||
| # ss = resnet50.conv1.weight.cpu().detach().numpy().reshape(-1) | ||||
| # ss = ss.tolist() | ||||
| # strs = '' | ||||
| # # for s in ss: | ||||
| # #     strs += str(s) + "," | ||||
| 
 | ||||
| # bs = struct.pack("f",1.0) | ||||
| # f = open('data.hex', 'wb') | ||||
| # f.write(bs) | ||||
| # f.close() | ||||
| # print(strs) | ||||
| # ssa = ss.array() | ||||
| 
 | ||||
| 
 | ||||
| ResNet50 = { | ||||
|     "conv1": "Conv2d", | ||||
|     "bn1": "BatchNorm2d", | ||||
|  | @ -313,21 +302,62 @@ def printDick(d, head, obj): | |||
| 
 | ||||
|   return strg | ||||
| 
 | ||||
| strg = '' | ||||
| strg = printDick(ResNet50, "RN50", resnet50) | ||||
| 
 | ||||
| ss = printDick(ResNet50, "RN50", resnet50) | ||||
| normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], | ||||
|                                  std=[0.229, 0.224, 0.225]) | ||||
| 
 | ||||
| weightfile.write(ss) | ||||
| val_loader = torch.utils.data.DataLoader( | ||||
|     datasets.ImageFolder(CurrentPath+'ImageNet/', transforms.Compose([ | ||||
|         transforms.Resize(256), | ||||
|         transforms.CenterCrop(224), | ||||
|         transforms.ToTensor(), | ||||
|         normalize, | ||||
|     ])), | ||||
|     batch_size=1, shuffle=False, | ||||
|     num_workers=1, pin_memory=True) | ||||
| 
 | ||||
| 
 | ||||
| for batch_idx, (data, target) in enumerate(val_loader): | ||||
| 
 | ||||
|     strg = strg + "int input_"+str(batch_idx)+"[]={" | ||||
|     array = data.cpu().detach().numpy().reshape(-1) | ||||
|     strg += str(currentbyte) + "," | ||||
|     for a in array: | ||||
|         bs = struct.pack("f", a) | ||||
|         binaryfile.write(bs) | ||||
|         currentbyte = currentbyte+1 | ||||
|     strg += str(currentbyte-1) + "," | ||||
|     strg = strg + "};\n" | ||||
| 
 | ||||
|     out = resnet50(data) | ||||
| 
 | ||||
|     strg = strg + "int output_"+str(batch_idx)+"[]={" | ||||
|     array = out.cpu().detach().numpy().reshape(-1) | ||||
|     strg += str(currentbyte) + "," | ||||
|     for a in array: | ||||
|         bs = struct.pack("f", a) | ||||
|         binaryfile.write(bs) | ||||
|         currentbyte = currentbyte+1 | ||||
|     strg += str(currentbyte-1) + "," | ||||
|     strg = strg + "};\n" | ||||
| 
 | ||||
| weightfile.write(strg) | ||||
| 
 | ||||
| binaryfile.close() | ||||
| weightfile.close() | ||||
| 
 | ||||
| print(ss) | ||||
| 
 | ||||
| print(strg) | ||||
| 
 | ||||
| print("===========================") | ||||
| print("===========================") | ||||
| print("===========================") | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # ResNet( | ||||
| #   (conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False) | ||||
| #   (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) | ||||
|  |  | |||