Skip to content

Instantly share code, notes, and snippets.

@shubham0204
Created April 4, 2019 11:47
Show Gist options
  • Save shubham0204/8244df7ea18b70f72aeba06715c255fd to your computer and use it in GitHub Desktop.
Save shubham0204/8244df7ea18b70f72aeba06715c255fd to your computer and use it in GitHub Desktop.
custom_images = recognizer.prepare_images_from_dir( 'custom_images/' )
class_1_images = recognizer.prepare_images_from_dir( 'images/p1/' )
class_2_images = recognizer.prepare_images_from_dir( 'images/p2/' )
scores = list()
labels = list()
for image in custom_images:
label = list()
score = list()
for sample in class_1_images :
image , sample = image.reshape( ( 1 , -1 ) ) , sample.reshape((1 , -1 ) )
score.append( recognizer.predict( [ image , sample ])[0] )
label.append( 0 )
for sample in class_2_images :
image , sample = image.reshape( ( 1 , -1 ) ) , sample.reshape((1 , -1 ) )
score.append( recognizer.predict( [ image , sample ])[0] )
label.append( 1 )
labels.append( label )
scores.append( score )
scores = np.array( scores )
labels = np.array( labels )
for i in range( custom_images.shape[0] ) :
index = np.argmax( scores[i] )
label_ = labels[i][index]
print( 'IMAGE {} is {} with confidence of {}'.format( i+1 , label_ , scores[i][index][0] ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment