keras

TypeError: tuple indices must be integers or slices, not list - While loading a model Keras

£可爱£侵袭症+ 提交于 2021-02-16 22:03:14
问题 In short, i have 2 trained models, one trained on 2 classes, the other on 3 classes. My code loads a model, loads an image, and predicts a classification result. finetune_model = tf.keras.models.load_model(modelPath) model = load_model(my_file) img = image.load_img(img_path, target_size=(img_width, img_height)) x = image.img_to_array(img) x = np.expand_dims(x, axis=0) x = preprocess_input(x) preds = model.predict(x) The model file is of .h5 type. When loading the 2-class trained model, it

Is dropout layer still active in a freezed Keras model (i.e. trainable=False)?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-16 21:27:25
问题 I have two trained models ( model_A and model_B ), and both of them have dropout layers. I have freezed model_A and model_B and merged them with a new dense layer to get model_AB (but I have not removed model_A 's and model_B 's dropout layers). model_AB 's weights will be non-trainable, except for the added dense layer. Now my question is: are the dropout layers in model_A and model_B active (i.e. drop neurons) when I am training model_AB ? 回答1: Short answer: The dropout layers will continue

Is dropout layer still active in a freezed Keras model (i.e. trainable=False)?

大兔子大兔子 提交于 2021-02-16 21:22:49
问题 I have two trained models ( model_A and model_B ), and both of them have dropout layers. I have freezed model_A and model_B and merged them with a new dense layer to get model_AB (but I have not removed model_A 's and model_B 's dropout layers). model_AB 's weights will be non-trainable, except for the added dense layer. Now my question is: are the dropout layers in model_A and model_B active (i.e. drop neurons) when I am training model_AB ? 回答1: Short answer: The dropout layers will continue

Split autoencoder on encoder and decoder keras

只愿长相守 提交于 2021-02-16 14:48:10
问题 I am trying to create an autoencoder for: Train the model Split encoder and decoder Visualise compressed data (encoder) Use arbitrary compressed data to get the output (decoder) from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2D from keras.models import Model from keras import backend as K from keras.datasets import mnist import numpy as np (x_train, _), (x_test, _) = mnist.load_data() x_train = x_train.astype('float32') / 255. x_train = x_train[:100,:,:,] x_test = x

Macro metrics (recall/F1…) for multiclass CNN

拈花ヽ惹草 提交于 2021-02-16 13:20:29
问题 I use CNN for image classification on unbalance dataset. I'm totaly new with tensorflow backend. It's multiclass problem (not multilabel) and I have 16 classes. Class are one hot encoded. I want to compute MACRO metrics for each epoch: F1, precision and recall. I found a code to print those Macro metrics but it's only work on validation set From: https://medium.com/@thongonary/how-to-compute-f1-score-for-each-epoch-in-keras-a1acd17715a2 class Metrics(Callback): def on_train_begin(self, logs={

Keras Recurrent Neural Networks For Multivariate Time Series

蹲街弑〆低调 提交于 2021-02-16 09:15:25
问题 I have been reading about Keras RNN models (LSTMs and GRUs), and authors seem to largely focus on language data or univariate time series that use training instances composed of previous time steps. The data I have is a bit different. I have 20 variables measured every year for 10 years for 100,000 persons as input data, and the 20 variables measured for year 11 as output data. What I would like to do is predict the value of one of the variables (not the other 19) for the 11th year. I have my

Keras: batch training for multiple large datasets

孤者浪人 提交于 2021-02-16 04:28:50
问题 this question regards the common problem of training on multiple large files in Keras which are jointly too large to fit on GPU memory. I am using Keras 1.0.5 and I would like a solution that does not require 1.0.6. One way to do this was described by fchollet here and here: # Create generator that yields (current features X, current labels y) def BatchGenerator(files): for file in files: current_data = pickle.load(open("file", "rb")) X_train = current_data[:,:-1] y_train = current_data[:,-1]

深度学习检测视频马赛克

大憨熊 提交于 2021-02-16 03:43:56
数据集二分类 第一类1000张, 第二类600张 1. darknet + resnet50 Loss,训练出来测试的时候是NULL, 暂时不知道为什么, 将CUDA-10.0 换成 cuda-8.0 依然显示不出label Loss 也是3.8 2. darknet + alexnet Loss = 3.8 , 3. keras + inceptionV3   1.) OpenCV4.0 调用失败, 提示FusedBatchNorm is_learning = True   2) https://github.com/opencv/opencv/issues/14236 修改代码,修复bug后,出现下面bug DataType = DT_BOOL 不被识别      3) 需要更新到最新版的opencv 4. keras + inception_resnetV2 同上 6. tensorflow + slim + inceptionV4 验证集准确率90%以上 , 但是OpenCV4.0 调用失败, slim 居然把DecodeJpeg层都加到 pb模型里去了, 暂时不知道怎么修改模型   1) 修改为 opencv 报错 :   2)修改为     opencv ---in 'Mul'   3) 修改为     opencv --- 错误同上 4) modify as call

对抗训练和对抗样本

十年热恋 提交于 2021-02-15 11:08:10
对抗训练 分类模型:对已有图片训练模型并分类 生成模型:分类模型的反向过程生成一张图片, 从一个类别向量反向生成一张图片 对抗样本 对图片通过算法增加一些噪声,变成新的图片,新的图片人眼无法分辨出变化,但是机器能分辨出来而且还会判错类别。 目前一些对抗样本生成算法: FGSM、FGMT:基于攻击者设置的对抗目标函数,利用梯度来优化原数据样本feature的值。 JSMA:基于模型输入输出之间的雅可比矩阵(Jacobian)来决定对输出影响最大的输入feature,进而改变这些feature来生成对抗样本。 DeepFool: 目的是寻找可以使分类器产生误判的最小扰动。简单理解就是点到分界面的各个最小距离。 开源项目 cleverhans Tensorflow下的子项目,完成了FGSM、FGMT、deepfool、CW2、JSMA等对抗样本攻击算法,提供tensorflow,keras,pytorch接口支持,可加载预训练模型。 https://github.com/tensorflow/cleverhans.git Foolbox 用来产生对抗样本的python工具箱,支持Pytorch、TensorFlow、Keras https://github.com/bethgelab/foolbox.git AdvBox 百度提供的AI模型安全工具箱,可产生对抗样本 https:/

Batch size for Stochastic gradient descent is length of training data and not 1?

让人想犯罪 __ 提交于 2021-02-15 07:10:25
问题 I am trying to plot the different learning outcome when using Batch gradient descent, Stochastic gradient descent and mini-batch stochastic gradient descent. Everywhere i look, i read that a batch_size=1 is the same as having a plain SGD and a batch_size=len(train_data) is the same as having the Batch gradient descent. I know that stochastic gradient descent is when you use only one single data sample for every update and batch gradient descent uses the entire training data set to compute the