This file contains 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 Generator(): | |
inputs = tf.keras.layers.Input(shape=[256, 256, 3]) | |
down_stack = [ | |
downsample(64, 4, apply_batchnorm=False), # (bs, 128, 128, 64) | |
downsample(128, 4), # (bs, 64, 64, 128) | |
downsample(256, 4), # (bs, 32, 32, 256) | |
downsample(512, 4), # (bs, 16, 16, 512) | |
downsample(512, 4), # (bs, 8, 8, 512) | |
downsample(512, 4), # (bs, 4, 4, 512) |
This file contains 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
class PointNet(nn.Module): | |
def __init__(self, classes = 10): | |
super().__init__() | |
self.transform = Transform() | |
self.fc1 = nn.Linear(1024, 512) | |
self.fc2 = nn.Linear(512, 256) | |
self.fc3 = nn.Linear(256, classes) | |
self.bn1 = nn.BatchNorm1d(512) |
This file contains 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 run_detector(detector, path): | |
img = load_img(path) | |
converted_img = tf.image.convert_image_dtype(img, tf.float32)[tf.newaxis, ...] | |
start_time = time.time() | |
result = detector(converted_img) | |
end_time = time.time() | |
result = {key:value.numpy() for key,value in result.items()} |
This file contains 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
class_to_explain = top_pred_classes[0] | |
simpler_model = LinearRegression() | |
simpler_model.fit(X=perturbations, y=predictions[:,:,class_to_explain], sample_weight=weights) | |
coeff = simpler_model.coef_[0] |
This file contains 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 tf_explain.callbacks.occlusion_sensitivity import OcclusionSensitivityCallback | |
import datetime | |
%load_ext tensorboard | |
log_dir = "logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") | |
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1) | |
o_callbacks = [OcclusionSensitivityCallback(validation_data=(vis_test, vis_lab),class_index=2,patch_size=4),] | |
model_TF.compile(optimizer=keras.optimizers.Adam(lr=0.001), loss='binary_crossentropy', metrics=[fbeta]) | |
model_TF.fit(vis_test, vis_lab, epochs=10, verbose=1, callbacks=[tensorboard_callback, o_callbacks]) |
This file contains 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
# Fully Connected Layer 6 | |
model.add(Dropout(0.2)) # 20% dropout of randomly selected nodes | |
model.add(Dense(10)) # final 10 FCN nodes | |
model.add(Activation('softmax')) # softmax activation | |
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) |