|
124 | 124 | "source": [ |
125 | 125 | "## Training the ResNet model\n", |
126 | 126 | "\n", |
127 | | - "In this demo, we are using [Caltech-256](http://www.vision.caltech.edu/Image_Datasets/Caltech256/) dataset, which contains 30608 images of 256 objects. For the training and validation data, we follow the splitting scheme in this MXNet [example](https://github.com/apache/incubator-mxnet/blob/master/example/image-classification/data/caltech256.sh). In particular, it randomly selects 60 images per class for training, and uses the remaining data for validation. The algorithm takes `RecordIO` file as input. The user can also provide the image files as input, which will be converted into `RecordIO` format using MXNet's [im2rec](https://mxnet.incubator.apache.org/how_to/recordio.html?highlight=im2rec) tool. It takes around 50 seconds to converted the entire Caltech-256 dataset (~1.2GB) on a p2.xlarge instance. However, for this demo, we will use record io format. \n", |
| 127 | + "In this demo, we are using [Caltech-256](http://www.vision.caltech.edu/Image_Datasets/Caltech256/) dataset, which contains 30608 images of 256 objects. For the training and validation data, we follow the splitting scheme in this MXNet [example](https://github.com/apache/incubator-mxnet/blob/master/example/image-classification/data/caltech256.sh). In particular, it randomly selects 60 images per class for training, and uses the remaining data for validation. The algorithm takes `RecordIO` file as input. The user can also provide the image files as input, which will be converted into `RecordIO` format using MXNet's [im2rec](https://mxnet.incubator.apache.org/how_to/recordio.html?highlight=im2rec) tool. It takes under a minute to convert the entire Caltech-256 dataset (~1.2GB) on a p3.2xlarge instance. However, for this demo, we will use record io format. \n", |
128 | 128 | "\n", |
129 | 129 | "Once we have the data available in the correct format for training, the next step is to actually train the model using the data. After setting training parameters, we kick off training, and poll for status until training is completed.\n", |
130 | 130 | "\n", |
|
149 | 149 | "cell_type": "markdown", |
150 | 150 | "metadata": {}, |
151 | 151 | "source": [ |
152 | | - "After setting training parameters, we kick off training, and poll for status until training is completed, which in this example, takes between 10 to 12 minutes per epoch on a p2.xlarge machine. The network typically converges after 10 epochs. However, to save the training time, we set the epochs to 2 but please keep in mind that it may not be sufficient to generate a good model. " |
| 152 | + "After setting training parameters, we kick off training, and poll for status until training is completed, which in this example, takes between 3 to 5 minutes per epoch on a p3.2xlarge machine. The network typically converges after 10 epochs. However, to save the training time, we set the epochs to 2 but please keep in mind that it may not be sufficient to generate a good model. " |
153 | 153 | ] |
154 | 154 | }, |
155 | 155 | { |
|
207 | 207 | " \"AlgorithmSpecification\": {\"TrainingImage\": training_image, \"TrainingInputMode\": \"File\"},\n", |
208 | 208 | " \"RoleArn\": role,\n", |
209 | 209 | " \"OutputDataConfig\": {\"S3OutputPath\": \"s3://{}/{}/output\".format(bucket, job_name_prefix)},\n", |
210 | | - " \"ResourceConfig\": {\"InstanceCount\": 1, \"InstanceType\": \"ml.p2.xlarge\", \"VolumeSizeInGB\": 50},\n", |
| 210 | + " \"ResourceConfig\": {\"InstanceCount\": 1, \"InstanceType\": \"ml.p3.2xlarge\", \"VolumeSizeInGB\": 50},\n", |
211 | 211 | " \"TrainingJobName\": job_name,\n", |
212 | 212 | " \"HyperParameters\": {\n", |
213 | 213 | " \"image_shape\": image_shape,\n", |
|
429 | 429 | " \"SplitType\": \"None\",\n", |
430 | 430 | " \"CompressionType\": \"None\",\n", |
431 | 431 | " },\n", |
432 | | - " \"TransformResources\": {\"InstanceType\": \"ml.p2.xlarge\", \"InstanceCount\": 1},\n", |
| 432 | + " \"TransformResources\": {\"InstanceType\": \"ml.c5.xlarge\", \"InstanceCount\": 1},\n", |
433 | 433 | "}\n", |
434 | 434 | "\n", |
435 | 435 | "print(\"Transform job name: {}\".format(batch_job_name))\n", |
|
821 | 821 | "metadata": {}, |
822 | 822 | "source": [ |
823 | 823 | "#### Create Endpoint\n", |
824 | | - "Next, the customer creates the endpoint that serves up the model, through specifying the name and configuration defined above. The end result is an endpoint that can be validated and incorporated into production applications. This takes 9-11 minutes to complete." |
| 824 | + "Next, the customer creates the endpoint that serves up the model, through specifying the name and configuration defined above. The end result is an endpoint that can be validated and incorporated into production applications." |
825 | 825 | ] |
826 | 826 | }, |
827 | 827 | { |
|
967 | 967 | "# the result will output the probabilities for all classes\n", |
968 | 968 | "# find the class with maximum probability and print the class index\n", |
969 | 969 | "index = np.argmax(result)\n", |
970 | | - "object_categories = [\n", |
971 | | - " \"ak47\",\n", |
972 | | - " \"american-flag\",\n", |
973 | | - " \"backpack\",\n", |
974 | | - " \"baseball-bat\",\n", |
975 | | - " \"baseball-glove\",\n", |
976 | | - " \"basketball-hoop\",\n", |
977 | | - " \"bat\",\n", |
978 | | - " \"bathtub\",\n", |
979 | | - " \"bear\",\n", |
980 | | - " \"beer-mug\",\n", |
981 | | - " \"billiards\",\n", |
982 | | - " \"binoculars\",\n", |
983 | | - " \"birdbath\",\n", |
984 | | - " \"blimp\",\n", |
985 | | - " \"bonsai-101\",\n", |
986 | | - " \"boom-box\",\n", |
987 | | - " \"bowling-ball\",\n", |
988 | | - " \"bowling-pin\",\n", |
989 | | - " \"boxing-glove\",\n", |
990 | | - " \"brain-101\",\n", |
991 | | - " \"breadmaker\",\n", |
992 | | - " \"buddha-101\",\n", |
993 | | - " \"bulldozer\",\n", |
994 | | - " \"butterfly\",\n", |
995 | | - " \"cactus\",\n", |
996 | | - " \"cake\",\n", |
997 | | - " \"calculator\",\n", |
998 | | - " \"camel\",\n", |
999 | | - " \"cannon\",\n", |
1000 | | - " \"canoe\",\n", |
1001 | | - " \"car-tire\",\n", |
1002 | | - " \"cartman\",\n", |
1003 | | - " \"cd\",\n", |
1004 | | - " \"centipede\",\n", |
1005 | | - " \"cereal-box\",\n", |
1006 | | - " \"chandelier-101\",\n", |
1007 | | - " \"chess-board\",\n", |
1008 | | - " \"chimp\",\n", |
1009 | | - " \"chopsticks\",\n", |
1010 | | - " \"cockroach\",\n", |
1011 | | - " \"coffee-mug\",\n", |
1012 | | - " \"coffin\",\n", |
1013 | | - " \"coin\",\n", |
1014 | | - " \"comet\",\n", |
1015 | | - " \"computer-keyboard\",\n", |
1016 | | - " \"computer-monitor\",\n", |
1017 | | - " \"computer-mouse\",\n", |
1018 | | - " \"conch\",\n", |
1019 | | - " \"cormorant\",\n", |
1020 | | - " \"covered-wagon\",\n", |
1021 | | - " \"cowboy-hat\",\n", |
1022 | | - " \"crab-101\",\n", |
1023 | | - " \"desk-globe\",\n", |
1024 | | - " \"diamond-ring\",\n", |
1025 | | - " \"dice\",\n", |
1026 | | - " \"dog\",\n", |
1027 | | - " \"dolphin-101\",\n", |
1028 | | - " \"doorknob\",\n", |
1029 | | - " \"drinking-straw\",\n", |
1030 | | - " \"duck\",\n", |
1031 | | - " \"dumb-bell\",\n", |
1032 | | - " \"eiffel-tower\",\n", |
1033 | | - " \"electric-guitar-101\",\n", |
1034 | | - " \"elephant-101\",\n", |
1035 | | - " \"elk\",\n", |
1036 | | - " \"ewer-101\",\n", |
1037 | | - " \"eyeglasses\",\n", |
1038 | | - " \"fern\",\n", |
1039 | | - " \"fighter-jet\",\n", |
1040 | | - " \"fire-extinguisher\",\n", |
1041 | | - " \"fire-hydrant\",\n", |
1042 | | - " \"fire-truck\",\n", |
1043 | | - " \"fireworks\",\n", |
1044 | | - " \"flashlight\",\n", |
1045 | | - " \"floppy-disk\",\n", |
1046 | | - " \"football-helmet\",\n", |
1047 | | - " \"french-horn\",\n", |
1048 | | - " \"fried-egg\",\n", |
1049 | | - " \"frisbee\",\n", |
1050 | | - " \"frog\",\n", |
1051 | | - " \"frying-pan\",\n", |
1052 | | - " \"galaxy\",\n", |
1053 | | - " \"gas-pump\",\n", |
1054 | | - " \"giraffe\",\n", |
1055 | | - " \"goat\",\n", |
1056 | | - " \"golden-gate-bridge\",\n", |
1057 | | - " \"goldfish\",\n", |
1058 | | - " \"golf-ball\",\n", |
1059 | | - " \"goose\",\n", |
1060 | | - " \"gorilla\",\n", |
1061 | | - " \"grand-piano-101\",\n", |
1062 | | - " \"grapes\",\n", |
1063 | | - " \"grasshopper\",\n", |
1064 | | - " \"guitar-pick\",\n", |
1065 | | - " \"hamburger\",\n", |
1066 | | - " \"hammock\",\n", |
1067 | | - " \"harmonica\",\n", |
1068 | | - " \"harp\",\n", |
1069 | | - " \"harpsichord\",\n", |
1070 | | - " \"hawksbill-101\",\n", |
1071 | | - " \"head-phones\",\n", |
1072 | | - " \"helicopter-101\",\n", |
1073 | | - " \"hibiscus\",\n", |
1074 | | - " \"homer-simpson\",\n", |
1075 | | - " \"horse\",\n", |
1076 | | - " \"horseshoe-crab\",\n", |
1077 | | - " \"hot-air-balloon\",\n", |
1078 | | - " \"hot-dog\",\n", |
1079 | | - " \"hot-tub\",\n", |
1080 | | - " \"hourglass\",\n", |
1081 | | - " \"house-fly\",\n", |
1082 | | - " \"human-skeleton\",\n", |
1083 | | - " \"hummingbird\",\n", |
1084 | | - " \"ibis-101\",\n", |
1085 | | - " \"ice-cream-cone\",\n", |
1086 | | - " \"iguana\",\n", |
1087 | | - " \"ipod\",\n", |
1088 | | - " \"iris\",\n", |
1089 | | - " \"jesus-christ\",\n", |
1090 | | - " \"joy-stick\",\n", |
1091 | | - " \"kangaroo-101\",\n", |
1092 | | - " \"kayak\",\n", |
1093 | | - " \"ketch-101\",\n", |
1094 | | - " \"killer-whale\",\n", |
1095 | | - " \"knife\",\n", |
1096 | | - " \"ladder\",\n", |
1097 | | - " \"laptop-101\",\n", |
1098 | | - " \"lathe\",\n", |
1099 | | - " \"leopards-101\",\n", |
1100 | | - " \"license-plate\",\n", |
1101 | | - " \"lightbulb\",\n", |
1102 | | - " \"light-house\",\n", |
1103 | | - " \"lightning\",\n", |
1104 | | - " \"llama-101\",\n", |
1105 | | - " \"mailbox\",\n", |
1106 | | - " \"mandolin\",\n", |
1107 | | - " \"mars\",\n", |
1108 | | - " \"mattress\",\n", |
1109 | | - " \"megaphone\",\n", |
1110 | | - " \"menorah-101\",\n", |
1111 | | - " \"microscope\",\n", |
1112 | | - " \"microwave\",\n", |
1113 | | - " \"minaret\",\n", |
1114 | | - " \"minotaur\",\n", |
1115 | | - " \"motorbikes-101\",\n", |
1116 | | - " \"mountain-bike\",\n", |
1117 | | - " \"mushroom\",\n", |
1118 | | - " \"mussels\",\n", |
1119 | | - " \"necktie\",\n", |
1120 | | - " \"octopus\",\n", |
1121 | | - " \"ostrich\",\n", |
1122 | | - " \"owl\",\n", |
1123 | | - " \"palm-pilot\",\n", |
1124 | | - " \"palm-tree\",\n", |
1125 | | - " \"paperclip\",\n", |
1126 | | - " \"paper-shredder\",\n", |
1127 | | - " \"pci-card\",\n", |
1128 | | - " \"penguin\",\n", |
1129 | | - " \"people\",\n", |
1130 | | - " \"pez-dispenser\",\n", |
1131 | | - " \"photocopier\",\n", |
1132 | | - " \"picnic-table\",\n", |
1133 | | - " \"playing-card\",\n", |
1134 | | - " \"porcupine\",\n", |
1135 | | - " \"pram\",\n", |
1136 | | - " \"praying-mantis\",\n", |
1137 | | - " \"pyramid\",\n", |
1138 | | - " \"raccoon\",\n", |
1139 | | - " \"radio-telescope\",\n", |
1140 | | - " \"rainbow\",\n", |
1141 | | - " \"refrigerator\",\n", |
1142 | | - " \"revolver-101\",\n", |
1143 | | - " \"rifle\",\n", |
1144 | | - " \"rotary-phone\",\n", |
1145 | | - " \"roulette-wheel\",\n", |
1146 | | - " \"saddle\",\n", |
1147 | | - " \"saturn\",\n", |
1148 | | - " \"school-bus\",\n", |
1149 | | - " \"scorpion-101\",\n", |
1150 | | - " \"screwdriver\",\n", |
1151 | | - " \"segway\",\n", |
1152 | | - " \"self-propelled-lawn-mower\",\n", |
1153 | | - " \"sextant\",\n", |
1154 | | - " \"sheet-music\",\n", |
1155 | | - " \"skateboard\",\n", |
1156 | | - " \"skunk\",\n", |
1157 | | - " \"skyscraper\",\n", |
1158 | | - " \"smokestack\",\n", |
1159 | | - " \"snail\",\n", |
1160 | | - " \"snake\",\n", |
1161 | | - " \"sneaker\",\n", |
1162 | | - " \"snowmobile\",\n", |
1163 | | - " \"soccer-ball\",\n", |
1164 | | - " \"socks\",\n", |
1165 | | - " \"soda-can\",\n", |
1166 | | - " \"spaghetti\",\n", |
1167 | | - " \"speed-boat\",\n", |
1168 | | - " \"spider\",\n", |
1169 | | - " \"spoon\",\n", |
1170 | | - " \"stained-glass\",\n", |
1171 | | - " \"starfish-101\",\n", |
1172 | | - " \"steering-wheel\",\n", |
1173 | | - " \"stirrups\",\n", |
1174 | | - " \"sunflower-101\",\n", |
1175 | | - " \"superman\",\n", |
1176 | | - " \"sushi\",\n", |
1177 | | - " \"swan\",\n", |
1178 | | - " \"swiss-army-knife\",\n", |
1179 | | - " \"sword\",\n", |
1180 | | - " \"syringe\",\n", |
1181 | | - " \"tambourine\",\n", |
1182 | | - " \"teapot\",\n", |
1183 | | - " \"teddy-bear\",\n", |
1184 | | - " \"teepee\",\n", |
1185 | | - " \"telephone-box\",\n", |
1186 | | - " \"tennis-ball\",\n", |
1187 | | - " \"tennis-court\",\n", |
1188 | | - " \"tennis-racket\",\n", |
1189 | | - " \"theodolite\",\n", |
1190 | | - " \"toaster\",\n", |
1191 | | - " \"tomato\",\n", |
1192 | | - " \"tombstone\",\n", |
1193 | | - " \"top-hat\",\n", |
1194 | | - " \"touring-bike\",\n", |
1195 | | - " \"tower-pisa\",\n", |
1196 | | - " \"traffic-light\",\n", |
1197 | | - " \"treadmill\",\n", |
1198 | | - " \"triceratops\",\n", |
1199 | | - " \"tricycle\",\n", |
1200 | | - " \"trilobite-101\",\n", |
1201 | | - " \"tripod\",\n", |
1202 | | - " \"t-shirt\",\n", |
1203 | | - " \"tuning-fork\",\n", |
1204 | | - " \"tweezer\",\n", |
1205 | | - " \"umbrella-101\",\n", |
1206 | | - " \"unicorn\",\n", |
1207 | | - " \"vcr\",\n", |
1208 | | - " \"video-projector\",\n", |
1209 | | - " \"washing-machine\",\n", |
1210 | | - " \"watch-101\",\n", |
1211 | | - " \"waterfall\",\n", |
1212 | | - " \"watermelon\",\n", |
1213 | | - " \"welding-mask\",\n", |
1214 | | - " \"wheelbarrow\",\n", |
1215 | | - " \"windmill\",\n", |
1216 | | - " \"wine-bottle\",\n", |
1217 | | - " \"xylophone\",\n", |
1218 | | - " \"yarmulke\",\n", |
1219 | | - " \"yo-yo\",\n", |
1220 | | - " \"zebra\",\n", |
1221 | | - " \"airplanes-101\",\n", |
1222 | | - " \"car-side-101\",\n", |
1223 | | - " \"faces-easy-101\",\n", |
1224 | | - " \"greyhound\",\n", |
1225 | | - " \"tennis-shoes\",\n", |
1226 | | - " \"toad\",\n", |
1227 | | - " \"clutter\",\n", |
1228 | | - "]\n", |
1229 | 970 | "print(\"Result: label - \" + object_categories[index] + \", probability - \" + str(result[index]))" |
1230 | 971 | ] |
1231 | 972 | }, |
|
0 commit comments