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 pathlib import Path | |
import cv2.cv2 as cv2 | |
import numpy as np | |
from cachier import cachier | |
ROOT_FOLDER = Path(__file__).resolve().parents[0] | |
CACHIER_FOLDER = ROOT_FOLDER / "cache" | |
NUMBER_OF_ITERATIONS = 5 |
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
# Binarize input image | |
gray_image = cv2.cvtColor(original_image, cv2.COLOR_RGB2GRAY) | |
show_image(gray_image, "Gray image") | |
binarized_image = cv2.adaptiveThreshold( | |
gray_image, | |
maxValue=1, | |
adaptiveMethod=cv2.ADAPTIVE_THRESH_GAUSSIAN_C, | |
thresholdType=cv2.THRESH_BINARY, | |
blockSize=9, |
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.cv2 as cv2 | |
import numpy as np | |
# Read the original image | |
IMAGES_FOLDER = "Path to your image folder" | |
original_image = cv2.imread(str(IMAGES_FOLDER / "spoon.jpg")) | |
# Define boundary rectangle containing the foreground object | |
height, width, _ = original_image.shape | |
left_margin_proportion = 0.3 |
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
N_EPOCH_SEARCH = 40 | |
tuner.search(x_train, y_train, epochs=N_EPOCH_SEARCH, validation_split=0.1) |
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
tuner.search_space_summary() |
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
HYPERBAND_MAX_EPOCHS = 40 | |
MAX_TRIALS = 20 | |
EXECUTION_PER_TRIAL = 2 |
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
# Show a summary of the search | |
tuner.results_summary() | |
# Retrieve the best model. | |
best_model = tuner.get_best_models(num_models=1)[0] | |
# Evaluate the best model. | |
loss, accuracy = best_model.evaluate(x_test, y_test) |
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
hp.Float( | |
'learning_rate', | |
min_value=1e-5, | |
max_value=1e-2, | |
sampling='LOG', | |
default=1e-3 | |
) |
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=keras.optimizers.Adam(1e-3), | |
loss='sparse_categorical_crossentropy', | |
metrics=['accuracy'] | |
) |
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
Dense( | |
units=hp.Int( | |
'units', | |
min_value=32, | |
max_value=512, | |
step=32, | |
default=128 | |
), | |
activation=hp.Choice( | |
'dense_activation', |
NewerOlder