models.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #
  4. # models.py
  5. #
  6. # Copyright 2022 Stephen Stengel <stephen.stengel@cwu.edu> and friends
  7. #
  8. import tensorflow as tf
  9. from keras.models import Sequential
  10. from keras.applications.inception_resnet_v2 import InceptionResNetV2
  11. from keras.layers import MaxPooling2D, Flatten, Dense, Dropout, GlobalAveragePooling2D
  12. from keras.losses import SparseCategoricalCrossentropy
  13. #So I only have to change it here
  14. def currentBestModel(shapeTupple):
  15. return inceptionResNetModel(shapeTupple)
  16. def inceptionResNetModel(shapeTupple):
  17. base_model = InceptionResNetV2(
  18. weights='imagenet',
  19. include_top=False,
  20. input_shape=shapeTupple
  21. )
  22. base_model.trainable = False
  23. incepnet = Sequential(
  24. [
  25. base_model,
  26. GlobalAveragePooling2D(),
  27. #MaxPooling2D(pool_size=(2, 2), padding='same'),
  28. #Dropout(0.1),
  29. #Flatten(),
  30. #Dense(64, activation='relu'),
  31. #Dense(64, activation='relu'),
  32. #Dense(32, activation='relu'),
  33. Dense(8, activation='softmax')
  34. ]
  35. )
  36. incepnet.compile(
  37. optimizer=tf.keras.optimizers.Adam(), # default learning rate is 0.001
  38. loss = SparseCategoricalCrossentropy(from_logits=False),
  39. metrics=['accuracy'])
  40. return incepnet