Package: googlenet-pytorch
GoogLeNet-PyTorchUpdate (Feb 17, 2020)The update is for ease of use and deployment.Example: Export to ONNXExample: Extract featuresExample: VisualIt is also now incredibly simple to load a pretrained model with a new number of classes for transfer learning:fromgooglenet_pytorchimportGoogLeNetmodel=GoogLeNet.from_pretrained('googlenet')OverviewThis repository contains an op-for-op PyTorch reimplementation ofGoing Deeper with Convolutions.The goal of this implementation is to be simple, highly extensible, and easy to integrate into your own projects. This implementation is a work in progress -- new features are currently being implemented.At the moment, you can easily:Load pretrained GoogLeNet modelsUse VGGNet models for classification or feature extractionUpcoming features: In the next few days, you will be able to:Quickly finetune an GoogLeNet on your own datasetExport GoogLeNet models for productionTable of contentsAbout GoogLeNetInstallationUsageLoad pretrained modelsExample: ClassifyExample: Extract featuresExample: Export to ONNXExample: VisualContributingAbout GoogLeNetIf you're new to GoogLeNet, here is an explanation straight from the official PyTorch implementation:We propose a deep convolutional neural network architecture codenamed "Inception",
which was responsible for setting the new state of the art for classification and
detection in the ImageNet Large-Scale Visual Recognition Challenge 2014 (ILSVRC 2014).
The main hallmark of this architecture is the improved utilization of the computing
resources inside the network. This was achieved by a carefully crafted design that allows
for increasing the depth and width of the network while keeping the computational budget
constant. To optimize quality, the architectural decisions were based on the Hebbian
principle and the intuition of multi-scale processing. One particular incarnation used
in our submission for ILSVRC 2014 is called GoogLeNet, a 22 layers deep network, the quality
of which is assessed in the context of classification and detection.InstallationInstall from pypi:$pipinstallgooglenet_pytorchInstall from source:$gitclonehttps://github.com/Lornatang/GoogLeNet-PyTorch.git
$cdGoogLeNet-PyTorch
$pipinstall-e.UsageLoading pretrained modelsLoad a pretrained GoogLeNet:fromgooglenet_pytorchimportGoogLeNetmodel=GoogLeNet.from_pretrained("googlenet")Their 1-crop error rates on imagenet dataset with pretrained models are listed below.Model structureTop-1 errorTop-5 errorgooglenet30.2210.47Example: ClassificationWe assume that in your current directory, there is aimg.jpgfile and alabels_map.txtfile (ImageNet class names). These are both included inexamples/simple.All pre-trained models expect input images normalized in the same way,
i.e. mini-batches of 3-channel RGB images of shape(3 x H x W), whereHandWare expected to be at least224.
The images have to be loaded in to a range of[0, 1]and then normalized usingmean = [0.485, 0.456, 0.406]andstd = [0.229, 0.224, 0.225].Here's a sample execution.importjsonimporttorchimporttorchvision.transformsastransformsfromPILimportImagefromgooglenet_pytorchimportGoogLeNet# Open imageinput_image=Image.open("img.jpg")# Preprocess imagepreprocess=transforms.Compose([transforms.Resize(256),transforms.CenterCrop(224),transforms.ToTensor(),transforms.Normalize(mean=[0.485,0.456,0.406],std=[0.229,0.224,0.225]),])input_tensor=preprocess(input_image)input_batch=input_tensor.unsqueeze(0)# create a mini-batch as expected by the model# Load class nameslabels_map=json.load(open("labels_map.txt"))labels_map=[labels_map[str(i)]foriinrange(1000)]# Classify with GoogLeNetmodel=GoogLeNet.from_pretrained("googlenet")model.eval()# move the input and model to GPU for speed if availableiftorch.cuda.is_available():input_batch=input_batch.to("cuda")model.to("cuda")withtorch.no_grad():logits=model(input_batch)preds=torch.topk(logits,k=5).indices.squeeze(0).tolist()print("-----")foridxinpreds:label=labels_map[idx]prob=torch.softmax(logits,dim=1)[0,idx].item()print(f"{label:<75}({prob*100:.2f}%)")Example: Feature ExtractionYou can easily extract features withmodel.extract_features:importtorchfromgooglenet_pytorchimportGoogLeNetmodel=GoogLeNet.from_pretrained('googlenet')# ... image preprocessing as in the classification example ...inputs=torch.randn(1,3,224,224)print(inputs.shape)# torch.Size([1, 3, 224, 224])features=model.extract_features(inputs)print(features.shape)# torch.Size([1, 1024, 7, 7])Example: Export to ONNXExporting to ONNX for deploying to production is now simple:importtorchfromgooglenet_pytorchimportGoogLeNetmodel=GoogLeNet.from_pretrained('googlenet')dummy_input=torch.randn(16,3,224,224)torch.onnx.export(model,dummy_input,"demo.onnx",verbose=True)Example: Visualcd $REPO$/framework
sh start.shThen open the browser and type in the browser addresshttp://127.0.0.1:10002/.Enjoy it.ImageNetSeeexamples/imagenetfor details about evaluating on ImageNet.For more datasets result. Please seeresearch/README.md.ContributingIf you find a bug, create a GitHub issue, or even better, submit a pull request. Similarly, if you have questions, simply post them as GitHub issues.I look forward to seeing what the community does with these models!CreditGoing Deeper with ConvolutionsChristian Szegedy1, Wei Liu2, Yangqing Jia1, Pierre Sermanet1, Scott Reed3, Dragomir Anguelov1, Dumitru Erhan1, Vincent Vanhoucke1, Andrew Rabinovich4AbstractWe propose a deep convolutional neural network architecture codenamed Inception that achieves the new
state of the art for classification and detection in the ImageNet Large-Scale Visual Recognition Challenge 2014
(ILSVRC14). The main hallmark of this architecture is the
improved utilization of the computing resources inside the
network. By a carefully crafted design, we increased the
depth and width of the network while keeping the computational budget constant. To optimize quality, the architectural decisions were based on the Hebbian principle and
the intuition of multi-scale processing. One particular incarnation used in our submission for ILSVRC14 is called
GoogLeNet, a 22 layers deep network, the quality of which
is assessed in the context of classification and detection.paper@article{AlexNet,
title:{Going Deeper with Convolutions},
author:{Christian Szegedy1, Wei Liu2, Yangqing Jia1, Pierre Sermanet1, Scott Reed3, Dragomir Anguelov1, Dumitru Erhan1, Vincent Vanhoucke1, Andrew Rabinovich4},
journal={cvpr},
year={2015}
}