Commit 6d9218ce authored by Diego André Sant'Ana's avatar Diego André Sant'Ana 🤞
Browse files

fix classification CNN with h.5

parent 07d28e2b
...@@ -22,7 +22,7 @@ from PIL import Image ...@@ -22,7 +22,7 @@ from PIL import Image
from keras import applications from keras import applications
from keras.preprocessing.image import ImageDataGenerator from keras.preprocessing.image import ImageDataGenerator
from keras import optimizers from keras import optimizers
from keras.models import Model, load_model from keras.models import Model
from keras.layers import Dropout, Flatten, Dense from keras.layers import Dropout, Flatten, Dense
from keras.callbacks import ModelCheckpoint, TensorBoard from keras.callbacks import ModelCheckpoint, TensorBoard
from keras import backend as K from keras import backend as K
...@@ -38,8 +38,8 @@ from collections import OrderedDict ...@@ -38,8 +38,8 @@ from collections import OrderedDict
from util.config import Config from util.config import Config
from util.file_utils import File from util.file_utils import File
from util.utils import TimeUtils from util.utils import TimeUtils
from tensorflow.keras.models import load_model
logger = logging.getLogger('PIL') logger = logging.getLogger('PIL')
logger.setLevel(logging.WARNING) logger.setLevel(logging.WARNING)
...@@ -60,7 +60,8 @@ dict_preprocessing[2] = applications.vgg19.preprocess_input, applications.vgg19. ...@@ -60,7 +60,8 @@ dict_preprocessing[2] = applications.vgg19.preprocess_input, applications.vgg19.
dict_preprocessing[3] = applications.resnet50.preprocess_input, applications.resnet50.decode_predictions dict_preprocessing[3] = applications.resnet50.preprocess_input, applications.resnet50.decode_predictions
dict_preprocessing[4] = applications.inception_v3.preprocess_input, applications.inception_v3.decode_predictions dict_preprocessing[4] = applications.inception_v3.preprocess_input, applications.inception_v3.decode_predictions
dict_preprocessing[5] = applications.mobilenet.preprocess_input, applications.mobilenet.decode_predictions dict_preprocessing[5] = applications.mobilenet.preprocess_input, applications.mobilenet.decode_predictions
dict_preprocessing[6] = applications.densenet.preprocess_input, applications.densenet.decode_predictions
dict_preprocessing[7] = applications.resnet_v2.preprocess_input, applications.resnet_v2.decode_predictions
class CNNKeras(Classifier): class CNNKeras(Classifier):
""" Class for CNN classifiers based on Keras applications """ """ Class for CNN classifiers based on Keras applications """
...@@ -370,6 +371,14 @@ class CNNKeras(Classifier): ...@@ -370,6 +371,14 @@ class CNNKeras(Classifier):
self.app = 5 self.app = 5
model = applications.MobileNet( model = applications.MobileNet(
weights="imagenet", include_top=False, input_shape=(IMG_WIDTH, IMG_HEIGHT, 3)) weights="imagenet", include_top=False, input_shape=(IMG_WIDTH, IMG_HEIGHT, 3))
elif self.architecture.value == "DenseNet201":
self.app = 6
model = applications.DenseNet201(
weights="imagenet", include_top=False, input_shape=(IMG_WIDTH, IMG_HEIGHT, 3))
elif self.architecture.value == "ResNet152V2":
self.app = 7
model = applications.ResNet152V2(
weights="imagenet", include_top=False, input_shape=(IMG_WIDTH, IMG_HEIGHT, 3))
for layer in model.layers[:int(len(model.layers) * (self.fine_tuning_rate.value / 100.0))]: for layer in model.layers[:int(len(model.layers) * (self.fine_tuning_rate.value / 100.0))]:
layer.trainable = False layer.trainable = False
...@@ -399,6 +408,14 @@ class CNNKeras(Classifier): ...@@ -399,6 +408,14 @@ class CNNKeras(Classifier):
self.app = 5 self.app = 5
model = applications.MobileNet( model = applications.MobileNet(
weights=None, include_top=False, input_shape=(IMG_WIDTH, IMG_HEIGHT, 3)) weights=None, include_top=False, input_shape=(IMG_WIDTH, IMG_HEIGHT, 3))
elif self.architecture.value == "DenseNet201":
self.app = 6
model = applications.DenseNet201(
weights=None, include_top=False, input_shape=(IMG_WIDTH, IMG_HEIGHT, 3))
elif self.architecture.value == "ResNet152V2":
self.app = 7
model = applications.ResNet152V2(
weights=None, include_top=False, input_shape=(IMG_WIDTH, IMG_HEIGHT, 3))
for layer in model.layers: for layer in model.layers:
layer.trainable = True layer.trainable = True
......
...@@ -619,6 +619,7 @@ class Act(object): ...@@ -619,6 +619,7 @@ class Act(object):
popup_info += "%-16s%-16s%0.2f%%\n" % (cl["name"].value, str(len_classes), (len_classes*100.0)/len_total) popup_info += "%-16s%-16s%0.2f%%\n" % (cl["name"].value, str(len_classes), (len_classes*100.0)/len_total)
print(popup_info) print(popup_info)
cv2.imwrite("rf2000.png",self._image)
self.tk.refresh_image(self._image) self.tk.refresh_image(self._image)
self.tk.popup(popup_info) self.tk.popup(popup_info)
else: else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment