对于前馈网络(FFN),可以轻松计算参数数量.鉴于CNN,LSTM等有一种快速查找keras模型中参数数量的方法吗?
使用Anaconda Python 2.7 Windows 10.
我正在使用Keras exmaple训练语言模型:
print('Build model...')
model = Sequential()
model.add(GRU(512, return_sequences=True, input_shape=(maxlen, len(chars))))
model.add(Dropout(0.2))
model.add(GRU(512, return_sequences=False))
model.add(Dropout(0.2))
model.add(Dense(len(chars)))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
def sample(a, temperature=1.0):
# helper function to sample an index from a probability array
a = np.log(a) / temperature
a = np.exp(a) / np.sum(np.exp(a))
return np.argmax(np.random.multinomial(1, a, 1))
# train the model, output generated text after each iteration
for iteration in range(1, 3):
print()
print('-' * 50)
print('Iteration', iteration)
model.fit(X, y, batch_size=128, nb_epoch=1)
start_index = random.randint(0, …Run Code Online (Sandbox Code Playgroud) 在Keras,我们可以将输出返回model.fit到历史记录,如下所示:
history = model.fit(X_train, y_train,
batch_size=batch_size,
nb_epoch=nb_epoch,
validation_data=(X_test, y_test))
Run Code Online (Sandbox Code Playgroud)
现在,如何将历史记录保存到文件中以供进一步使用(例如,绘制针对时期的acc或loss的绘制图)?
我正在研究一种图像类增量分类器方法,使用CNN作为特征提取器和一个完全连接的块进行分类.
首先,我对每个训练有素的VGG网络进行了微调,以完成一项新任务.一旦网络被训练用于新任务,我就为每个班级存储一些示例,以避免在新班级可用时忘记.
当某些类可用时,我必须计算样本的每个输出,包括新类的示例.现在为旧类的输出添加零,并在新类输出上添加与每个新类对应的标签,我有新标签,即:如果有3个新类输入....
旧班类型输出: [0.1, 0.05, 0.79, ..., 0 0 0]
新类类型输出:[0.1, 0.09, 0.3, 0.4, ..., 1 0 0]**最后的输出对应于类.
我的问题是,我如何改变自定义的损失函数来训练新的类?我想要实现的损失函数定义为:
蒸馏损失对应于旧类别的输出以避免遗忘,而分类损失对应于新类别.
如果你能给我一些代码样本来改变keras中的损失函数会很好.
谢谢!!!!!
computer-vision deep-learning conv-neural-network keras loss-function
我认为对于 GPU 内存较低的 PyTorch 用户来说,这是一个非常普遍的信息:
RuntimeError: CUDA out of memory. Tried to allocate MiB (GPU ; GiB total capacity; GiB already allocated; MiB free; cached)
Run Code Online (Sandbox Code Playgroud)
我想为我的课程研究对象检测算法。许多深度学习架构需要大容量的 GPU 内存,所以我的机器无法训练这些模型。我尝试通过将每一层加载到 GPU 然后将其加载回来来处理图像:
RuntimeError: CUDA out of memory. Tried to allocate MiB (GPU ; GiB total capacity; GiB already allocated; MiB free; cached)
Run Code Online (Sandbox Code Playgroud)
但它似乎不是很有效。我想知道在使用很少的 GPU 内存的同时训练大型深度学习模型是否有任何提示和技巧。提前致谢!
编辑:我是深度学习的初学者。如果这是一个愚蠢的问题,请道歉:)
两天前我开始玩TensorFlow,我想知道是否有三重奏和实施的对比损失.
我一直在查看文档,但我没有找到关于这些内容的任何示例或描述.
Drop-Out是正规化技术.并且我想将它应用于非MNIST数据以减少过度拟合以完成我的Udacity深度学习课程作业.我已经阅读了关于如何调用的tensorflow文档tf.nn.dropout.这是我的代码
# before proceeding further.
from __future__ import print_function
import numpy as np
import tensorflow as tf
from six.moves import cPickle as pickle
pickle_file = 'notMNIST.pickle'
with open(pickle_file, 'rb') as f:
save = pickle.load(f)
train_dataset = save['train_dataset']
train_labels = save['train_labels']
valid_dataset = save['valid_dataset']
valid_labels = save['valid_labels']
test_dataset = save['test_dataset']
test_labels = save['test_labels']
del save # hint to help gc free up memory
print('Training set', train_dataset.shape, train_labels.shape)
print('Validation set', valid_dataset.shape, valid_labels.shape)
print('Test set', test_dataset.shape, test_labels.shape)
image_size = 28 …Run Code Online (Sandbox Code Playgroud) 我想设计一个带有一个(或多个)卷积层(CNN)和一个或多个完全连接的隐藏层的深网.
对于具有完全连接层的深度网络,在无人监督的预训练中有一些方法,例如,使用去噪自动编码器或RBM.
我的问题是:我如何实现(在theano中)卷积层的无监督预训练阶段?
我不希望完整的实现作为答案,但我希望链接到一个好的教程或可靠的参考.
python neural-network unsupervised-learning theano deep-learning
我是TensorFlow和机器学习的新手.我试图将两个物体分类为杯子和pendrive(jpeg图像).我成功地训练并导出了一个model.ckpt.现在我正在尝试恢复已保存的model.ckpt以进行预测.这是脚本:
import tensorflow as tf
import math
import numpy as np
from PIL import Image
from numpy import array
# image parameters
IMAGE_SIZE = 64
IMAGE_CHANNELS = 3
NUM_CLASSES = 2
def main():
image = np.zeros((64, 64, 3))
img = Image.open('./IMG_0849.JPG')
img = img.resize((64, 64))
image = array(img).reshape(64,64,3)
k = int(math.ceil(IMAGE_SIZE / 2.0 / 2.0 / 2.0 / 2.0))
# Store weights for our convolution and fully-connected layers
with tf.name_scope('weights'):
weights = {
# 5x5 conv, 3 input channel, 32 …Run Code Online (Sandbox Code Playgroud) deep-learning ×10
python ×5
keras ×4
tensorflow ×4
low-memory ×1
nlp ×1
numpy ×1
pytorch ×1
theano ×1