我有一个用于二进制图像分类的convnet模型:cat/dog.
library(keras)
conv_base <- application_vgg16(
weights = "imagenet",
include_top = FALSE,
input_shape = c(150, 150, 3)
)
# Hyperparameter construction
model <- keras_model_sequential() %>%
conv_base %>%
layer_flatten() %>%
layer_dense(units = 256, activation = "relu") %>%
layer_dense(units = 1, activation = "sigmoid")
model %>% compile(
loss = "binary_crossentropy",
optimizer = optimizer_rmsprop(lr = 2e-5),
metrics = c("accuracy")
)
img <- image_load('test_image.jpg', target_size = c(150, 150))
x <- image_to_array(img)
x <- array_reshape(x, c(1, dim(x)))
preds_class <- model %>% predict_classes(x)
model %>% predict(x)
Run Code Online (Sandbox Code Playgroud)
在 …
tidytext书中有一些示例,主题模型更加整洁:
library(tidyverse)
library(tidytext)
library(topicmodels)
library(broom)
year_word_counts <- tibble(year = c("2007", "2008", "2009"),
+ word = c("dog", "cat", "chicken"),
+ n = c(1753L, 1157L, 1057L))
animal_dtm <- cast_dtm(data = year_word_counts, document = year, term = word, value = n)
animal_lda <- LDA(animal_dtm, k = 5, control = list( seed = 1234))
animal_lda <- tidy(animal_lda, matrix = "beta")
# Console output
Error in as.data.frame.default(x) :
cannot coerce class "structure("LDA_VEM", package = "topicmodels")" to a data.frame
In addition: Warning message:
In tidy.default(animal_lda, matrix …Run Code Online (Sandbox Code Playgroud)