This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from keras.wrappers.scikit_learn import KerasClassifier | |
| from sklearn.metrics import f1_score, make_scorer | |
| from sklearn.model_selection import GridSearchCV | |
| from keras.models import Sequential | |
| from keras.layers import GlobalAveragePooling2D | |
| from keras.layers import Dense | |
| from keras.optimizers import RMSprop | |
| def build_model(learning_rate): | |
| Resnet50_model = Sequential() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from keras import backend as K | |
| def recall(y_true, y_pred): | |
| """Recall for each labels. | |
| Args: | |
| y_ture: 1d array-like, or label indicator array. | |
| y_pred: 1d array-like, or label indicator array. | |
| Return: | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import cv2 | |
| import numpy as np | |
| from matplotlib import pyplot as plt | |
| def intensity_hist(image_file): | |
| """show some descriptive stats of some of the most relevant aspects in the dataset. | |
| Such as the min, max, median, mean of the image sizes. | |
| Args: | |
| image_files: string. Path of image file. | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import cv2 | |
| import pandas as pd | |
| def stats(image_files): | |
| """show some descriptive stats of some of the most relevant aspects in the dataset. | |
| Such as the min, max, median, mean of the image sizes. | |
| Args: | |
| image_files: sequence of string. Paths of image files. | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| %matplotlib inline | |
| plt.figure(figsize=(24, 4)) | |
| plt.subplots_adjust(hspace=0.4) | |
| ax1 = plt.subplot(1, 1, 1) | |
| sns.countplot(x=(np.where(train_targets == 1))[1], ax=ax1) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def Resnet50_predict_breed(img_path): | |
| """Return the dog breed that is predicted by the transer learing model. | |
| Args: | |
| img_path: string. a file path to a color images. | |
| Returns: | |
| dog breed: string, and probability: float. | |
| """ | |
| bottleneck_feature = extract_Resnet50(path_to_tensor(img_path)) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Resnet50_model = Sequential() | |
| Resnet50_model.add(GlobalAveragePooling2D(input_shape=train_Resnet50.shape[1:])) | |
| Resnet50_model.add(Dense(133, activation='softmax')) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | train_Resnet50 = extract_Resnet50(paths_to_tensor(train_files).astype('float32')) | |
| valid_Resnet50 = extract_Resnet50(paths_to_tensor(valid_files).astype('float32')) | |
| test_Resnet50 = extract_Resnet50(paths_to_tensor(test_files).astype('float32')) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from keras.applications.resnet50 import ResNet50, preprocess_input | |
| def extract_Resnet50(tensor): | |
| """Extracting bottleneck features of ResNet-50 to use as input our classifying model. | |
| Args: | |
| tensor: numpy.array. a 4D tensor suitable for supplying to a Keras CNN. | |
| Retruns: | |
| numpy.array, bottleneck features of ResNet-50 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=[f1]) | 
NewerOlder