我想知道是否可以保存部分训练的Keras模型并在再次加载模型后继续训练.
这样做的原因是我将来会有更多的训练数据,我不想再次重新训练整个模型.
我正在使用的功能是:
#Partly train model
model.fit(first_training, first_classes, batch_size=32, nb_epoch=20)
#Save partly trained model
model.save('partly_trained.h5')
#Load partly trained model
from keras.models import load_model
model = load_model('partly_trained.h5')
#Continue training
model.fit(second_training, second_classes, batch_size=32, nb_epoch=20)
Run Code Online (Sandbox Code Playgroud)
编辑1:添加了完整的工作示例
使用10个时期之后的第一个数据集,最后一个纪元的损失将为0.0748,准确度为0.9863.
保存,删除和重新加载模型后,在第二个数据集上训练的模型的损失和准确性将分别为0.1711和0.9504.
这是由新的训练数据还是完全重新训练的模型引起的?
"""
Model by: http://machinelearningmastery.com/
"""
# load (downloaded if needed) the MNIST dataset
import numpy
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense
from keras.utils import np_utils
from keras.models import load_model
numpy.random.seed(7)
def baseline_model():
model = Sequential()
model.add(Dense(num_pixels, input_dim=num_pixels, init='normal', …
Run Code Online (Sandbox Code Playgroud) 当我运行keras脚本时,我得到以下输出:
Using TensorFlow backend.
2017-06-14 17:40:44.621761: W
tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow
library wasn't compiled to use SSE4.1 instructions, but these are
available on your machine and could speed up CPU computations.
2017-06-14 17:40:44.621783: W
tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow
library wasn't compiled to use SSE4.2 instructions, but these are
available on your machine and could speed up CPU computations.
2017-06-14 17:40:44.621788: W
tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow
library wasn't compiled to use AVX instructions, but these are
available on your machine and could speed up …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在iOS应用程序中使用Google Analytics,我看到了这部分代码:
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
Run Code Online (Sandbox Code Playgroud)
作为iOS开发的初学者,我不知道id<GAITracker> tracker
和之间有什么区别GAITracker *tracker
.我在谷歌搜索过它,但没有找到解释.有人可以为我澄清一下吗?
我在Ubuntu 16.04上使用Keras和Theano后端.我的设置一直没有问题,但是,当我导入Keras(import keras
)时突然出现以下错误:
ValueError:您正在尝试使用旧的GPU后端.它是从Theano中删除的.现在使用device = cuda*.有关更多信息,请参阅https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29.
我该如何解决这个问题?
我最近从https://github.com/floydhub/dl-docker运行深度学习docker ,在尝试教程时,在导入keras图层模块时收到错误.
from __future__ import print_function
import keras
from keras.datasets import cifar10
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Conv2D, MaxPooling2D
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-13-3a12c6f32fcf> in <module>()
5 from keras.models import Sequential
6 from keras.layers import Dense, Dropout, Activation, Flatten
----> 7 from keras.layers import Conv2D, MaxPooling2D
ImportError: cannot import name Conv2D
Run Code Online (Sandbox Code Playgroud)
我在ipython笔记本上使用ubuntu 14.04,python版本2.7.6以及docker上的以下版本的深度学习库运行.
ARG THEANO_VERSION=rel-0.8.2
ARG TENSORFLOW_VERSION=0.12.1
ARG TENSORFLOW_ARCH=cpu
ARG KERAS_VERSION=1.2.0
ARG …
Run Code Online (Sandbox Code Playgroud) 在我闪亮的仪表板中,我有几个selectizeInput类型的下拉菜单。它们位于页面底部,因此我不想向下打开下拉菜单,而是向上打开它们。
我确实找到了名为pickerInput 的下拉菜单的解决方案。这里的解决方案是添加一个标签:shinyWidgets
css
.dropdown-menu{bottom: 100%; top: auto;}
Run Code Online (Sandbox Code Playgroud)
但是,此标记不适用于selectizeInput
. 知道css
我必须添加到我的脚本中吗?
编辑(maartenzam 举例回答)
library(shiny)
ui <- fluidPage(
# selectize style
tags$head(tags$style(type = "text/css", paste0(".selectize-dropdown {
bottom: 100% !important;
top:auto!important;
}}"))),
div(style='height:200px'),
selectizeInput('id', 'test', 1:10, selected = NULL, multiple = FALSE,
options = NULL)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud) 假设我已经训练了下面的模型一个时代:
model = Sequential([
Dense(32, input_dim=784), # first number is output_dim
Activation('relu'),
Dense(10), # output_dim, input_dim is taken for granted from above
Activation('softmax'),
])
Run Code Online (Sandbox Code Playgroud)
我得到了第一个隐藏层(命名为)的权重dense1_w
,偏差和单个数据样本.dense1_b
dense1
sample
如何使用这些得到的输出dense1
上sample
的keras
?
谢谢!
根据Keras文档,辍学图层显示了培训和测试阶段的不同行为:
请注意,如果您的模型在训练和测试阶段具有不同的行为(例如,如果它使用Dropout,BatchNormalization等),您将需要将学习阶段标志传递给您的函数:
不幸的是,没有人谈论实际的差异.为什么辍学在测试阶段表现不同?我希望该层将一定数量的神经元设置为0.为什么这种行为取决于训练/测试阶段?
我是从多个384x286 b/w图像手动创建我的数据集.
我加载这样的图像:
x = []
for f in files:
img = Image.open(f)
img.load()
data = np.asarray(img, dtype="int32")
x.append(data)
x = np.array(x)
Run Code Online (Sandbox Code Playgroud)
这导致x是一个数组(num_samples,286,384)
print(x.shape) => (100, 286, 384)
Run Code Online (Sandbox Code Playgroud)
阅读keras文档,并检查我的后端,我应该向卷积步骤提供由(行,列,通道)组成的input_shape
因为我不随意知道样本大小,我本来希望传递一个类似的输入大小
( None, 286, 384, 1 )
Run Code Online (Sandbox Code Playgroud)
该模型构建如下:
model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=input_shape))
# other steps...
Run Code Online (Sandbox Code Playgroud)
传递为input_shape(286,384,1)会导致:
检查输入时出错:预期conv2d_1_input有4个维度,但是有形状的数组(85,286,384)
传递as_input_shape(无,286,384,1)会导致:
输入0与图层conv2d_1不兼容:预期ndim = 4,发现ndim = 5
我究竟做错了什么 ?我如何重塑输入数组?
我想在导航栏页面中设置 tabPanels 标题的颜色。我尝试了不同的方法,但无法弄清楚如何去做。下面是一个可重现的示例。我也尝试了其他方法,但没有任何效果。
library(shiny)
ui <-shinyUI(bootstrapPage(
"",
navbarPage(
tags$style(HTML("
.tabbable > .nav > a {font-weight: bold; color:black}
.tabbable > .nav > li > a[data-value='t1'] {color:red}
.tabbable > .nav > li > a[data-value='t2'] {color:blue}
.tabbable > .nav > li > a[data-value='t3'] {color:green}
.tabbable > .nav > li[class=active] > a {color:aqua}
")),
tabPanel("t0",h2("normal tab")),
tabPanel("t1",h2("red tab")),
tabPanel("t2",h2("blue tab")),
tabPanel("t3",h2("green tab")),
tabPanel("t4",h2("normal tab")),
tabPanel("t5",h2("normal tab"))
)
))
server <- function(input, output) {}
shinyApp(ui=ui,server=server)
Run Code Online (Sandbox Code Playgroud) keras ×7
python ×6
tensorflow ×6
theano ×3
css ×2
html ×2
r ×2
shiny ×2
convolution ×1
ios ×1
keras-layer ×1
navbar ×1
objective-c ×1