Skip to content

Instantly share code, notes, and snippets.

View ogyalcin's full-sized avatar

Orhan Yalcin ogyalcin

View GitHub Profile
Property Symbolic AI Subsymbolic AI
Knowledge Coding Easy | Coded as Rules and Relations Easy | Coded in Networks
Theoretical Knowledge Acquisition Easy Difficult
New Knowledge Insertion Easy Difficult
Result Explanation Easily Explained Difficult | Usually Opaque Models
Development Difficult | Manually Entering Rules Difficult | Can be Long
Training Difficult Easy
Approximate or Incomplete Information Processing Cannot Adopt by Itself Can Deal
Managing and Maintaining Difficult Easy
Processing Mode Sequential and Slow Parallel and Fast
@ogyalcin
ogyalcin / dash.css
Created June 7, 2021 20:35 — forked from gschivley/dash.css
Dash styleguide by Chris P
/* Table of contents
––––––––––––––––––––––––––––––––––––––––––––––––––
- Plotly.js
- Grid
- Base Styles
- Typography
- Links
- Buttons
- Forms
- Lists
tf.keras.preprocessing.image.save_img('stylized-image.png', image[0])
import IPython.display as display
image = tf.Variable(content_image)
epochs = 20
steps_per_epoch = 100
step = 0
for n in range(epochs):
for m in range(steps_per_epoch):
step += 1
train_step(image)
total_variation_weight=500
@tf.function()
def train_step(image):
with tf.GradientTape() as tape:
outputs = extractor(image)
loss = style_content_loss(outputs)
loss += total_variation_weight*tf.image.total_variation(image)
grad = tape.gradient(loss, image)
# Create an optimizer. The paper recommends LBFGS, but Adam works okay, too:
opt = tf.optimizers.Adam(learning_rate=0.005, beta_1=0.99, epsilon=1e-1)
# To optimize this, use a weighted combination of the two losses to get the total loss:
style_weight=1e-2
content_weight=1e4
def style_content_loss(outputs):
style_outputs = outputs['style']
content_outputs = outputs['content']
class StyleContentModel(tf.keras.models.Model):
def __init__(self, style_layers, content_layers):
super(StyleContentModel, self).__init__()
# The main
self.vgg = vgg_layers(style_layers + content_layers)
self.vgg.trainable = False
# Used as keys in dict creation
self.style_layers = style_layers
# We will use block5 conv2 layer for content
content_layers = ['block5_conv2']
# We will use conv1 layers from every block for style
style_layers = ['block1_conv1','block2_conv1','block3_conv1', 'block4_conv1','block5_conv1']
def gram_matrix(input_tensor):
# Tensor contraction over specified indices and outer product.
# Matrix multiplication
result = tf.linalg.einsum('bijc,bijd->bcd', input_tensor, input_tensor)
# Save the shape of the input tensor
input_shape = tf.shape(input_tensor)
# Casts a tensor to a new type.
num_locations = tf.cast(input_shape[1]*input_shape[2], tf.float32)
# Divide matrix multiplication output to num_locations
return result/(num_locations)
# Creates a pre-trained VGG model which takes an input and returns a list of intermediate output values
def vgg_layers(layer_names):
""" Creates a vgg model that returns a list of intermediate output values."""
# Load our model. Load pretrained VGG, trained on imagenet data
vgg = tf.keras.applications.VGG19(include_top=False, weights='imagenet')
vgg.trainable = False
outputs = [vgg.get_layer(name).output for name in layer_names]
model = tf.keras.Model([vgg.input], outputs)
return model