Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

## ---------------------------- ## ## ## sample_student.py ## import numpy as np #It's kk to import whatever you want from the local util module if you

## ---------------------------- ##
##
## sample_student.py
##
import numpy as np
#It's kk to import whatever you want from the local util module if you would like:
#from util.X import ...
def classify(im):
'''
Example submission for coding challenge.
Args: im (nxmx3) unsigned 8-bit color image
Returns: One of three strings: 'brick', 'ball', or 'cylinder'
'''
#Let's guess randomly! Maybe we'll get lucky.
labels = ['brick', 'ball', 'cylinder']
random_integer = np.random.randint(low = 0, high = 3)
return labels[random_integer]

Instructions

Write a method classify.py that takes in an image and returns a prediction - ball, brick, or cylinder.

An example script in located in challenge/sample_student.py

Your script will be automatically evaluated on a set of test images.

The testing images are quite similar to the training images, and organized into the same difficulty categories.

You are allowed 10 submissions to the evaluation server, which will provide immediate feedback.

The Data

Easy Examples

image text in transcribed

## ------------------------- ##
##
## evaluate.py
## Basic image processing utilties.
##
##
## ------------------------- ##
import numpy as np
import glob
from easydict import EasyDict
from matplotlib.pyplot import imread
#Import student's method:
from sample_student import classify
dataset_names = ['easy', 'medium_1', 'medium_2', 'hard']
weights = [0.5, 0.2, 0.2, 0.1]
classes = ['ball', 'brick', 'cylinder']
data_path = '../data' #Assuming data is stored in current directory.
dataset_weights = {}
for i in range(len(dataset_names)):
dataset_weights[dataset_names[i]] = weights[i]
#Store data performance data in a nested easydict:
performance = EasyDict()
#Iterate through images:
for dataset_name in dataset_names:
performance[dataset_name] = EasyDict()
performance[dataset_name]['overall'] = np.array([0, 0]) #overall Correct/incorrect
for image_class in classes:
performance[dataset_name][image_class] = np.array([0, 0])
image_paths = glob.glob(data_path + '/'
+ dataset_name + '/'
+ image_class + '/*.jpg')
for image_path in image_paths:
im = imread(image_path)
prediction = classify(im)
if image_class == prediction:
performance[dataset_name][image_class][0] += 1
else:
performance[dataset_name][image_class][1] += 1
#Tally overall performance for class
performance[dataset_name]['overall'] = performance[dataset_name]['overall'] \
+ performance[dataset_name][image_class]
#Print out errors:
print('Fraction of Correct Predictions: ')
overall_accuracy = 0
for dataset_name in dataset_names:
total_correct, total_incorrect = performance[dataset_name]['overall']
total = total_correct + total_incorrect
accuracy = np.round(float(total_correct)/total, 4)
overall_accuracy += accuracy * dataset_weights[dataset_name]
performance[dataset_name]['accuracy'] = accuracy
print(dataset_name + ': ' + \
'(' + str(total_correct) + '/' + str(total) + ' = ' + \
str(accuracy) + ')')
for image_class in classes:
print(' ' + image_class + ': '
+ str(performance[dataset_name][image_class][0])
+ '/'
+ str(np.sum(performance[dataset_name][image_class])))
overall_accuracy = np.round(overall_accuracy, 2)
score = 0
if overall_accuracy >= 0.6:
score = 10
elif overall_accuracy >= 0.55:
score = 9
elif overall_accuracy >= 0.5:
score = 8
elif overall_accuracy >= 0.45:
score = 7
elif overall_accuracy >= 0.4:
score = 6
elif overall_accuracy >= 0.35:
score = 5
elif overall_accuracy >= 0:
score = 4
print(" Overall Accuracy = ", overall_accuracy)

print("Score = ", score)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

Write a note on job design.

Answered: 1 week ago

Question

Compute the derivative of f(x)cos(-4/5x)

Answered: 1 week ago

Question

Discuss the process involved in selection.

Answered: 1 week ago

Question

Differentiate tan(7x+9x-2.5)

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago