- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Can you please explain the below code line by line, highly appreciate it
dim=(224,224)
EXAMPLES_BASE_DIR='../../'
_________________________*_
get labels
_________________________*_
labels_file=EXAMPLES_BASE_DIR+'data/ilsvrc12/synset_words.txt'
labels=numpy.loadtxt(labels_file,str,delimiter='\t')
_________________________*_
configure the NCS
_________________________*_
mvnc.SetGlobalOption(mvnc.GlobalOption.LOG_LEVEL, 2)
_________________________*_
Get a list of ALL the sticks that are plugged in
_________________________*_
devices = mvnc.EnumerateDevices()
if len(devices) == 0:
print('No devices found')
quit()
_________________________*_
Pick the first stick to run the network
_________________________*_
device = mvnc.Device(devices[0])
_________________________*_
Open the NCS
_________________________*_
device.OpenDevice()
network_blob='graph'
Load blob
with open(network_blob, mode='rb') as f:
blob = f.read()
graph = device.AllocateGraph(blob)
_________________________*_
Load the image
_________________________*_
ilsvrc_mean = numpy.load(EXAMPLES_BASE_DIR+'data/ilsvrc12/ilsvrc_2012_mean.npy').mean(1).mean(1) #loading the mean file
img = cv2.imread(EXAMPLES_BASE_DIR+'data/images/nps_electric_guitar.png')
img=cv2.resize(img,dim)
img = img.astype(numpy.float32)
img[:,:,0] = (img[:,:,0] - ilsvrc_mean[0])
img[:,:,1] = (img[:,:,1] - ilsvrc_mean[1])
img[:,:,2] = (img[:,:,2] - ilsvrc_mean[2])
_________________________*_
Send the image to the NCS
_________________________*_
graph.LoadTensor(img.astype(numpy.float16), 'user object')
_________________________*_
Get the result from the NCS
_________________________*_
output, userobj = graph.GetResult()
_________________________*_
Print the results of the inference form the NCS
_________________________*_
order = output.argsort()[::-1][:6]
print('\n------- predictions --------')
for i in range(0,5):
print ('prediction ' + str(i) + ' (probability ' + str(output[order[i]]) + ') is ' + labels[order[i]] + ' label index is: ' + str(order[i]) )
_________________________*_
Clean up the graph and the device
_________________________*_
graph.DeallocateGraph()
device.CloseDevice()
- 태그:
- Loading
링크가 복사됨
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
@muhammadyou You can find a step-by-step explanation of the typical API workflow @ https://movidius.github.io/blog/ncs-image-classifier/
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
@muhammadyou Labels are usually just a string that describes the category within a model.
Regarding the mean, it is calculated from the training data set and is commonly used for mean subtraction. Subtracting the mean will usually create a "centering" effect in the input data.
Afterwards, the input data is usually divided by the standard deviation causing the input data to be scaled down. Subtracting the mean and dividing by the standard deviation is usually known as feature scaling and is a common technique used to accelerate gradient descent convergence.
You can read more about blobs at http://caffe.berkeleyvision.org/tutorial/net_layer_blob.html.