How to use test_generator method in pyresttest

Best Python code snippet using pyresttest_python

test - Copy.py

Source:test - Copy.py Github

copy

Full Screen

1<<<<<<< HEAD2# Imports3import cv24import keras5import time6import numpy as np7from keras import optimizers8from models.vgg16_model import vgg16_finetuned9from datagenerator.datagenerator import test_datagenerator10from keras.preprocessing.image import load_img11from IPython.display import display12from PIL import Image13from keras.models import load_model14test_dir = 'dataset/test'15# Load the trained model16print('loading trained model...')17new_model = load_model('trained_models/model1.h5')18print('loading complete')19# Print the summary of the loaded model20print('summary of loaded model')21new_model.summary()22# Load test images23print('reading test images...')24test_generator = test_datagenerator()25# Get the filenames from the generator26fnames = test_generator.filenames27# Get the ground truth from generator28ground_truth = test_generator.classes29# Get the label to class mapping from the generator30label2index = test_generator.class_indices31# Getting the mapping from class index to class label32idx2label = dict((v, k) for k, v in label2index.items())33# Get the predictions from the model using the generator34print('predicting on the test images...')35prediction_start = time.clock()36predictions = new_model.predict_generator(test_generator,37 steps=test_generator.samples / test_generator.batch_size,38 verbose=0)39prediction_finish = time.clock()40prediction_time = prediction_finish - prediction_start41predicted_classes = np.argmax(predictions, axis=1)42errors = np.where(predicted_classes != ground_truth)[0]43print("No. of errors = {}/{}".format(len(errors), test_generator.samples))44correct_predictions = np.where(predicted_classes == ground_truth)[0]45print("No. of correct predictions = {}/{}".format(len(correct_predictions), test_generator.samples))46print("Test Accuracy = {0:.2f}%".format(len(correct_predictions)*100/test_generator.samples))47print("Predicted in {0:.3f} minutes!".format(prediction_time/60))48# original = load_img('{}/{}'.format(test_dir, fnames[correct_predictions[2]]))49# print(original)50# # Show the errors51# for i in range(len(errors)):52# pred_class = np.argmax(predictions[errors[i]])53# pred_label = idx2label[pred_class]54#55# title = 'Original label:{}, Prediction :{}, confidence : {:.3f}'.format(56# fnames[errors[i]].split('/')[0],57# pred_label,58# predictions[errors[i]][pred_class])59#60# original = load_img('{}/{}'.format(test_dir, fnames[errors[i]]))61# plt.figure(figsize=[7, 7])62# plt.axis('off')63# plt.title(title)64# plt.imshow(original)65# plt.show()66#67# # Show the correct predictions68# for i in range(len(correct_predictions)):69# pred_class = np.argmax(predictions[correct_predictions[i]])70# pred_label = idx2label[pred_class]71#72# title = 'Original label:{}, Prediction :{}, confidence : {:.3f}'.format(73# fnames[correct_predictions[i]].split('/')[0],74# pred_label,75# predictions[correct_predictions[i]][pred_class])76#77# original = load_img('{}/{}'.format(test_dir, fnames[correct_predictions[i]]))78# plt.figure(figsize=[7, 7])79# plt.axis('off')80# plt.title(title)81# plt.imshow(original)82=======83# Imports84import cv285import keras86import time87import numpy as np88from keras import optimizers89from models.vgg16_model import vgg16_finetuned90from datagenerator.datagenerator import test_datagenerator91from keras.preprocessing.image import load_img92from IPython.display import display93from PIL import Image94from keras.models import load_model95test_dir = 'dataset/test'96# Load the trained model97print('loading trained model...')98new_model = load_model('trained_models/model1.h5')99print('loading complete')100# Print the summary of the loaded model101print('summary of loaded model')102new_model.summary()103# Load test images104print('reading test images...')105test_generator = test_datagenerator()106# Get the filenames from the generator107fnames = test_generator.filenames108# Get the ground truth from generator109ground_truth = test_generator.classes110# Get the label to class mapping from the generator111label2index = test_generator.class_indices112# Getting the mapping from class index to class label113idx2label = dict((v, k) for k, v in label2index.items())114# Get the predictions from the model using the generator115print('predicting on the test images...')116prediction_start = time.clock()117predictions = new_model.predict_generator(test_generator,118 steps=test_generator.samples / test_generator.batch_size,119 verbose=0)120prediction_finish = time.clock()121prediction_time = prediction_finish - prediction_start122predicted_classes = np.argmax(predictions, axis=1)123errors = np.where(predicted_classes != ground_truth)[0]124print("No. of errors = {}/{}".format(len(errors), test_generator.samples))125correct_predictions = np.where(predicted_classes == ground_truth)[0]126print("No. of correct predictions = {}/{}".format(len(correct_predictions), test_generator.samples))127print("Test Accuracy = {0:.2f}%".format(len(correct_predictions)*100/test_generator.samples))128print("Predicted in {0:.3f} minutes!".format(prediction_time/60))129# original = load_img('{}/{}'.format(test_dir, fnames[correct_predictions[2]]))130# print(original)131# # Show the errors132# for i in range(len(errors)):133# pred_class = np.argmax(predictions[errors[i]])134# pred_label = idx2label[pred_class]135#136# title = 'Original label:{}, Prediction :{}, confidence : {:.3f}'.format(137# fnames[errors[i]].split('/')[0],138# pred_label,139# predictions[errors[i]][pred_class])140#141# original = load_img('{}/{}'.format(test_dir, fnames[errors[i]]))142# plt.figure(figsize=[7, 7])143# plt.axis('off')144# plt.title(title)145# plt.imshow(original)146# plt.show()147#148# # Show the correct predictions149# for i in range(len(correct_predictions)):150# pred_class = np.argmax(predictions[correct_predictions[i]])151# pred_label = idx2label[pred_class]152#153# title = 'Original label:{}, Prediction :{}, confidence : {:.3f}'.format(154# fnames[correct_predictions[i]].split('/')[0],155# pred_label,156# predictions[correct_predictions[i]][pred_class])157#158# original = load_img('{}/{}'.format(test_dir, fnames[correct_predictions[i]]))159# plt.figure(figsize=[7, 7])160# plt.axis('off')161# plt.title(title)162# plt.imshow(original)163>>>>>>> 2ca6a6a72573981894106df4e30dd0bd62f05584...

Full Screen

Full Screen

random.py

Source:random.py Github

copy

Full Screen

...166 print 'TWOPI =', TWOPI167 print 'LOG4 =', LOG4168 print 'NV_MAGICCONST =', NV_MAGICCONST169 print 'SG_MAGICCONST =', SG_MAGICCONST170 test_generator(N, 'random()')171 test_generator(N, 'normalvariate(0.0, 1.0)')172 test_generator(N, 'lognormvariate(0.0, 1.0)')173 test_generator(N, 'cunifvariate(0.0, 1.0)')174 test_generator(N, 'expovariate(1.0)')175 test_generator(N, 'vonmisesvariate(0.0, 1.0)')176 test_generator(N, 'gammavariate(0.5, 1.0)')177 test_generator(N, 'gammavariate(0.9, 1.0)')178 test_generator(N, 'gammavariate(1.0, 1.0)')179 test_generator(N, 'gammavariate(2.0, 1.0)')180 test_generator(N, 'gammavariate(20.0, 1.0)')181 test_generator(N, 'gammavariate(200.0, 1.0)')182 test_generator(N, 'gauss(0.0, 1.0)')183 test_generator(N, 'betavariate(3.0, 3.0)')184def test_generator(n, funccall):185 import time186 print n, 'times', funccall187 code = compile(funccall, funccall, 'eval')188 sum = 0.0189 sqsum = 0.0190 smallest = 1e10191 largest = -1e10192 t0 = time.time()193 for i in range(n):194 x = eval(code)195 sum = sum + x196 sqsum = sqsum + x*x197 smallest = min(x, smallest)198 largest = max(x, largest)...

Full Screen

Full Screen

problem5test.py

Source:problem5test.py Github

copy

Full Screen

1#Euler Problem 5 Test23import unittest4import problem556class TestProblem5(unittest.TestCase):7 8 def test_count_generator(self):9 test_generator = problem5.count_generator(2520,20)10 self.assertEqual(next(test_generator), 2520)11 self.assertEqual(next(test_generator), 2540)12 self.assertEqual(next(test_generator), 2560)13 14 test_generator = problem5.count_generator(2,3)15 self.assertEqual(next(test_generator), 2)16 self.assertEqual(next(test_generator), 5)17 self.assertEqual(next(test_generator), 8)18 19 def test_is_multiple_of_integers_under_19(self):20 self.assertEqual(problem5.is_multiple_of_integers_under_19(2520), False)21 self.assertEqual(problem5.is_multiple_of_integers_under_19(670442572800), True)22 23 def test_smallest_multiple(self):24 self.assertEqual(problem5.smallest_multiple(), 232792560)25 26if __name__ == '__main__': ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyresttest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful