Looking at the mxnet documentation.
It takes the pretrained squeenext1_1 weights, and sets imagenet_hotdog_index variable to 713.
net = models.squeezenet1_1(pretrained=True, prefix='deep_dog_', ctx=contexts) # hot dog happens to be a class in imagenet. # we can reuse the weight for that class for better performance # here's the index for that class for later use imagenet_hotdog_index = 713
Then they set a 2 class output layer on top of it
deep_dog_net = models.squeezenet1_1(prefix='deep_dog_', classes=2) deep_dog_net.collect_params().initialize(ctx=contexts) deep_dog_net.features = net.features print(deep_dog_net)
Where I get confused is in the classify_hotog function - it is applying softmax to the output layer, and then returning the highest result index. This would make perfect sense if we had somehow told the network to compare against index 713. But it is called for prediction before the index variable is being reused? How does the network know the class to compare against is index 713/hot dog? We've basically taken squeezenet and reduced it down to 2 class output. But how does the network know what class to compare it to? Why would it give a high probability to the second argument/class when showing a hotdog - seems to me it shouldn't know what class it is comparing it to?
out = mx.nd.SoftmaxActivation(net(image.as_in_context(contexts))) print('Probabilities are: '+str(out.asnumpy())) result = np.argmax(out.asnumpy())
I would have expected it to maybe use the full squeezenet output layer, and set something like
if np.argmax(out.asnumpy()) == 713: "Hot Dog!' Else: "Not hot dog!"
Never understood this and would appreciate if anyone could help me get this detail.