Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_set_eval.py 1.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  1. import numpy as np
  2. from .support import path_update
  3. from tensorflow.keras.preprocessing.image import ImageDataGenerator
  4. def test_eval(model):
  5. test_dir = '../../datasets/validation/'
  6. #te_heart_dir, te_brain_dir, te_eye_dir, te_kidney_dir, te_skull_dir = path_update(test_dir,classes)
  7. test_gen_tmp = ImageDataGenerator(rescale=1/225.)
  8. test_gen = test_gen_tmp.flow_from_directory(test_dir,
  9. target_size=(224, 224),
  10. color_mode='rgb',
  11. class_mode='categorical',
  12. batch_size=20,
  13. shuffle=False,
  14. seed=42)
  15. STEP_SIZE_TEST = test_gen.n // test_gen.batch_size
  16. #test_gen.reset()
  17. pred = model.predict_generator(test_gen,
  18. steps=STEP_SIZE_TEST+1,
  19. verbose=1)
  20. predicted_class_indices = np.argmax(pred, axis=1)
  21. labels = (test_gen.class_indices)
  22. class_to_int = dict((k, v) for k, v in labels.items())
  23. img_classes = test_gen.filenames
  24. #print(img_classes)
  25. test_y = [j.split("\\")[0] for j in img_classes]
  26. test_gen = [class_to_int[i] for i in test_y]
  27. return predicted_class_indices,test_gen
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...