Description Usage Arguments Value Examples
Perform A Single Gradient Ascent
1 | ascend(model, input, loss, gradient, lr = 1)
|
model |
A keras model. |
input |
The input to perturb. |
loss |
The output from |
gradient |
The output from |
lr |
The learning rate used to update input. |
The perturbed input.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | library(keras)
library(caress)
data(iris)
x <- as.matrix(iris[,1:4])
y <- to_categorical(as.numeric(iris[,5])-1)
input <- from_input(x, name = "input")
output <- input %>%
layer_dense(units = 2, activation = "linear", name = "middle") %>%
to_output(y, name = "output")
model <- prepare(input, output)
build(model, x, y, epochs = 10, batch_size = 8)
loss <- get_layer_loss(model, "middle")
gradient <- get_layer_gradient(model, loss)
x <- matrix(runif(4), 1, 4)
for(i in 1:20){
x <- ascend(model, x, loss, gradient)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.