diff --git "a/stackoverflow_DL-related_questions_data/data15.json" "b/stackoverflow_DL-related_questions_data/data15.json" new file mode 100644--- /dev/null +++ "b/stackoverflow_DL-related_questions_data/data15.json" @@ -0,0 +1,3000 @@ +{"QuestionId":52586526,"AnswerCount":1,"Tags":"","CreationDate":"2018-10-01T07:40:08.327","AcceptedAnswerId":52596030.0,"OwnerUserId":10345968.0,"Title":"Caffe model fails to learn","Body":"

I have the following convolutional model implemented in Keras, where after training for 100,000 epoch, it shows excellent performance with greate accuracy.<\/p>\n\n

img_rows, img_cols = 24, 15\ninput_shape = (img_rows, img_cols, 1)\nnb_filters = 32\npool_size = (2, 2)\nkernel_size = (3, 3)\n\nmodel = Sequential()\nmodel.add(Convolution2D(nb_filters, kernel_size[0], kernel_size[1],\n                        border_mode='valid',\n                        input_shape=input_shape))\nmodel.add(Activation('relu'))\nmodel.add(Convolution2D(nb_filters, kernel_size[0], kernel_size[1]))\nmodel.add(Activation('relu'))\nmodel.add(MaxPooling2D(pool_size=pool_size))\nmodel.add(Dropout(0.25))\n\nmodel.add(Flatten())\nmodel.add(Dense(128))\nmodel.add(Activation('relu'))\nmodel.add(Dropout(0.5))\nmodel.add(Dense(nb_classes))\nmodel.add(Activation('softmax'))\n\nmodel.compile(loss='categorical_crossentropy',\n              optimizer='adadelta',\n              metrics=['accuracy'])\n<\/code><\/pre>\n\n

However after trying to implement the same model in Caffe, it fails to train with an almost fixed loss value >=2.1 && <=2.6. \nHere is my Caffe prototext implementation:<\/p>\n\n

name: \"FneishNet\"\nlayer {\n  name: \"inlayer1\"\n  type: \"Data\"\n  top: \"data\"\n  top: \"label\"\n  include {\n    phase: TRAIN\n  }\n  data_param {\n    source: \"examples\/fneishnet_numbers\/fneishnet_numbers_train_lmdb\"\n    batch_size: 128\n    backend: LMDB\n  }\n}\nlayer {\n  name: \"inlayer1\"\n  type: \"Data\"\n  top: \"data\"\n  top: \"label\"\n  include {\n    phase: TEST\n  }\n  data_param {\n    source: \"examples\/fneishnet_numbers\/fneishnet_numbers_val_lmdb\"\n    batch_size: 64\n    backend: LMDB\n  }\n}\nlayer {\n  name: \"conv1\"\n  type: \"Convolution\"\n  bottom: \"data\"\n  top: \"conv1\"\n  param {\n    lr_mult: 1\n    decay_mult: 1\n  }\n  param {\n    lr_mult: 2\n  }\n  convolution_param {\n    num_output: 32\n    kernel_size: 3\n    stride: 1\n    weight_filler {\n      type: \"xavier\"\n    }\n    bias_filler {\n      type: \"constant\"\n    }\n  }\n}\nlayer {\n  name: \"relu1\"\n  type: \"ReLU\"\n  bottom: \"conv1\"\n  top: \"conv1\"\n}\nlayer {\n  name: \"conv2\"\n  type: \"Convolution\"\n  bottom: \"conv1\"\n  top: \"conv2\"\n  param {\n    lr_mult: 1\n    decay_mult: 1\n  }\n  param {\n    lr_mult: 2\n  }\n  convolution_param {\n    num_output: 32\n    kernel_size: 3\n    stride: 1\n    weight_filler {\n      type: \"xavier\"\n    }\n    bias_filler {\n      type: \"constant\"\n    }\n  }\n}\nlayer {\n  name: \"relu2\"\n  type: \"ReLU\"\n  bottom: \"conv2\"\n  top: \"conv2\"\n}\nlayer {\n  name: \"pool1\"\n  type: \"Pooling\"\n  bottom: \"conv2\"\n  top: \"pool1\"\n  pooling_param {\n    pool: MAX\n    kernel_size: 2\n    stride: 1\n  }\n}\nlayer {\n  name: \"drop1\"\n  type: \"Dropout\"\n  bottom: \"pool1\"\n  top: \"pool1\"\n  dropout_param {\n    dropout_ratio: 0.25\n  }\n}\nlayer {\n  name: \"flatten1\"\n  type: \"Flatten\"\n  bottom: \"pool1\"\n  top: \"flatten1\"\n}\nlayer {\n  name: \"fc1\"\n  type: \"InnerProduct\"\n  bottom: \"flatten1\"\n  top: \"fc1\"\n  param {\n    lr_mult: 1\n  }\n  param {\n    lr_mult: 2\n  }\n  inner_product_param {\n    num_output: 128\n    weight_filler {\n      type: \"xavier\"\n    }\n    bias_filler {\n      type: \"constant\"\n    }\n  }\n}\nlayer {\n  name: \"relu3\"\n  type: \"ReLU\"\n  bottom: \"fc1\"\n  top: \"fc1\"\n}\nlayer {\n  name: \"drop2\"\n  type: \"Dropout\"\n  bottom: \"fc1\"\n  top: \"fc1\"\n  dropout_param {\n    dropout_ratio: 0.5\n  }\n}\nlayer {\n  name: \"fc2\"\n  type: \"InnerProduct\"\n  bottom: \"fc1\"\n  top: \"fc2\"\n  param {\n    lr_mult: 1\n  }\n  param {\n    lr_mult: 2\n  }\n  inner_product_param {\n    num_output: 11\n    weight_filler {\n      type: \"xavier\"\n    }\n    bias_filler {\n      type: \"constant\"\n    }\n  }\n}\nlayer {\n  name: \"accuracy\"\n  type: \"Accuracy\"\n  bottom: \"fc2\"\n  bottom: \"label\"\n  top: \"accuracy\"\n  include {\n    phase: TEST\n  }\n}\nlayer {\n  name: \"loss\"\n  type: \"SoftmaxWithLoss\"\n  bottom: \"fc2\"\n  bottom: \"label\"\n  top: \"loss\"\n}\n<\/code><\/pre>\n\n

And here is my model solver (hyper-parameters):<\/p>\n\n

net: \"models\/fneishnet_numbers\/train_val.prototxt\"\ntest_iter: 1000\ntest_interval: 4000\ntest_initialization: false\ndisplay: 40\naverage_loss: 40\nbase_lr: 0.01\ngamma: 0.1\nlr_policy: \"poly\"\npower: 0.5\nmax_iter: 3000000\nmomentum: 0.9\nweight_decay: 0.0005\nsnapshot: 100000\nsnapshot_prefix: \"models\/fneishnet_numbers\/fneishnet_numbers_quick\"\nsolver_mode: CPU\n<\/code><\/pre>\n\n

I believe that if i have no problem translating the model into Caffe, then it should performs the same way it do in Keras, so i think i had missed something.\nAny help would be appreciated, thanks.<\/p>\n","answers":[{"AnswerId":"52596030","CreationDate":"2018-10-01T17:27:00.517","ParentId":null,"OwnerUserId":"3802483","Title":null,"Body":"

poly: the effective learning rate follows a polynomial decay, to be\n\/\/ zero by the max_iter. return base_lr (1 - iter\/max_iter) ^ (power)<\/p>\n\n

So basically, are you sure you want to keep power set to 0.5 in\nreturns base_lr (1 - iter\/max_iter) ^ (power)? I think that might be the problem as you are decaying to minus something, try 2?<\/p>\n"}]} +{"QuestionId":52586787,"AnswerCount":0,"Tags":"","CreationDate":"2018-10-01T07:58:27.707","AcceptedAnswerId":null,"OwnerUserId":6933148.0,"Title":"How to solve the tensorflow's Conv2d layer error: \"self.kernel_size[i], IndexError: tuple index out of range\"?","Body":"

I'm running my programs with tensorflow 1.8.0<\/code> and keras 2.2.2<\/code> \nI have the following model architecture:<\/p>\n\n

in1 = Input(name='in1', shape=(None, 1))\nin2 = Input(name='in2', shape=(None, 1))\nembedding = Embedding(1000, 50)\ne_in1 = embedding(in1)\ne_in2 = embedding(in2)\ncross = Dot(axes=[3, 3], normalize=False)([e_in1, e_in2])\ncross = Conv2D(1, 3, activation='relu', name=\"conv\", padding='same')(cross)\n<\/code><\/pre>\n\n

But arriving at the Conv2D<\/code> layer, I've got the following error:<\/p>\n\n

\n

Traceback (most recent call last):<\/p>\n \n

\n

File\n \"\/usr\/local\/lib\/python3.5\/dist-packages\/IPython\/core\/interactiveshell.py\",\n line 2910, in run_code\n exec(code_obj, self.user_global_ns, self.user_ns) File \"\", line 1, in \n cross = Conv2D(1, 3, activation='relu', name=\"conv\", padding='same')(cross) File\n \"\/usr\/local\/lib\/python3.5\/dist-packages\/keras\/engine\/base_layer.py\",\n line 474, in call<\/strong>\n output_shape = self.compute_output_shape(input_shape) File \"\/usr\/local\/lib\/python3.5\/dist-packages\/keras\/layers\/convolutional.py\",\n line 195, in compute_output_shape\n self.kernel_size[i], IndexError: tuple index out of range<\/p>\n <\/blockquote>\n<\/blockquote>\n\n

I saw here<\/a> solutions related to the keras version, but I don't think it's the same here, because my keras version worked well with another program that uses the same layer Conv2D<\/code>.\n Anyone can give me some tips, please?\nThanks in advance<\/p>\n","answers":[]} +{"QuestionId":52586853,"AnswerCount":1,"Tags":"","CreationDate":"2018-10-01T08:03:07.277","AcceptedAnswerId":null,"OwnerUserId":785041.0,"Title":"Batchnormalization nodes wrongfully linked with each other","Body":"

I'm training a Keras network using BatchNormalization layers and saw a strange thing looking at the TensorBoard graph. My network consists of a stack of 1D convolutions followed by BatchNormalization layers. Most of the graph seems fine, but the very first BatchNormalization layer is - according to TensorBoard - sending information to all other BatchNormalization layers. Is this normal?<\/p>\n\n

Here's the output of the network according to Keras model.summary()<\/code><\/p>\n\n

| Layer (type)                    | Output Shape      | Param # | Connected to        |\n|---------------------------------|-------------------|---------|---------------------|\n| pt_cloud_0 (InputLayer)         | (None, None, 39)  | 0       |                     |\n| pt_cloud_1 (InputLayer)         | (None, None, 39)  | 0       |                     |\n| conv1d_0_0 (Conv1D)             | (None, None, 64)  | 2560    | pt_cloud_0[0][0]    |\n| conv1d_1_0 (Conv1D)             | (None, None, 64)  | 2560    | pt_cloud_1[0][0]    |\n| batchnorm_0_0 (BatchNormalizati | (None, None, 64)  | 256     | conv1d_0_0[0][0]    |\n| batchnorm_1_0 (BatchNormalizati | (None, None, 64)  | 256     | conv1d_1_0[0][0]    |\n| conv1d_0_1 (Conv1D)             | (None, None, 64)  | 4160    | batchnorm_0_0[0][0] |\n| conv1d_1_1 (Conv1D)             | (None, None, 64)  | 4160    | batchnorm_1_0[0][0] |\n| batchnorm_0_1 (BatchNormalizati | (None, None, 64)  | 256     | conv1d_0_1[0][0]    |\n| batchnorm_1_1 (BatchNormalizati | (None, None, 64)  | 256     | conv1d_1_1[0][0]    |\n| conv1d_0_2 (Conv1D)             | (None, None, 316) | 20540   | batchnorm_0_1[0][0] |\n| conv1d_1_2 (Conv1D)             | (None, None, 316) | 20540   | batchnorm_1_1[0][0] |\n| batchnorm_0_2 (BatchNormalizati | (None, None, 316) | 1264    | conv1d_0_2[0][0]    |\n| batchnorm_1_2 (BatchNormalizati | (None, None, 316) | 1264    | conv1d_1_2[0][0]    |\n| conv1d_0_3 (Conv1D)             | (None, None, 316) | 100172  | batchnorm_0_2[0][0] |\n| conv1d_1_3 (Conv1D)             | (None, None, 316) | 100172  | batchnorm_1_2[0][0] |\n| aux_in (InputLayer)             | (None, 46)        | 0       | 0                   |\n| batchnorm_0_3 (BatchNormalizati | (None, None, 316) | 1264    | conv1d_0_3[0][0]    |\n| batchnorm_1_3 (BatchNormalizati | (None, None, 316) | 1264    | conv1d_1_3[0][0]    |\n| aux_dense_0 (Dense)             | (None, 384)       | 18048   | aux_in[0][0]        |\n| global_max_0 (GlobalMaxPooling1 | (None, 316)       | 0       | batchnorm_0_3[0][0] |\n| global_max_1 (GlobalMaxPooling1 | (None, 316)       | 0       | batchnorm_1_3[0][0] |\n| aux_dense_1 (Dense)             | (None, 384)       | 147840  | aux_dense_0[0][0]   |\n| concatenate_1 (Concatenate)     | (None, 1016)      | 0       | global_max_0[0][0]  |\n|                                 |                   |         | global_max_1[0][0]  |\n|                                 |                   |         | aux_dense_1[0][0]   |\n| dense_0 (Dense)                 | (None, 384)       | 390528  | concatenate_1[0][0] |\n| dropout_0 (Dropout)             | (None, 384)       | 0       | dense_0[0][0]       |\n| dense_1 (Dense)                 | (None, 384)       | 147840  | dropout_0[0][0]     |\n| prediction (Dense)              | (None, 101)       | 38885   | dense_1[0][0]       |\n<\/code><\/pre>\n\n

And here's (part of) the graph shown in TensorBoard \"graph\"\n(If the image is not visible, please go to this link: https:\/\/imgur.com\/a\/G74uIWE<\/a>)\nZoomed version: \"zoomed_graph\" or this link: https:\/\/imgur.com\/a\/vtF3VWb<\/a> <\/p>\n\n

The red-outlined layer is the very first batch normalization layer I made in the network (batchnorm_0_0). I don't know much about the inner workings of a batchnormalization layer but I find it odd that it is linked to all other BN-layers, while those other BN-layers do not (they just are connected to the input\/output I assigned them).\nI'm wondering if this is a bug in my code, in keras, or maybe in TensorBoard?<\/p>\n\n

Update:<\/strong> model's code below; it's written in a way I can easily experiment with the number of convolution layers\/filters, etc... but should be rather explanatory.<\/p>\n\n

def _build(self, conv_filter_counts, dense_counts, dense_dropout_rates=None):\n    \"\"\"\n    Builds the model. The model will have the following architecture:\n      (1) [Per pointcloud] N 1D convolution layers (with possibly different depths) followed by BatchNormalization\n                           layers.\n      (2) [Per pointcloud] A global max pooling layer (calculating a 'global feature' of the point cloud).\n      (3) [Once] M dense layers (with possibly different amounts of neurons), optionally followed by DropOut layers.\n      (4) [Once] A final dense layer with `self.class_count` neurons and softmax activation.\n\n    Arguments:\n      conv_filter_counts: A list (length N) containing the succesive 1D convolution filter depths in (1)\n      dense_counts: A list (length M) containing the amount of succesive neurons in (3)\n      dense_dropout_rates: Optional. If specified, must be a list of length M containing the dropout rates\n                           for each corresponding dense layer specified by `dense_counts`. Individual entries\n                           can be set to None to disable dropout.\n                           If not specified, dropout is applied nowhere.\n    \"\"\"\n    inputs = [Input(shape=(None, self.pt_dim), name='pt_cloud_{}'.format(i)) for i in range(self.input_count)]\n    if self.aux_input_count > 0:\n        aux_input = Input(shape=(self.aux_input_count,), name='aux_in')\n\n    if self.spatial_subnet:\n        # Predict and apply spatial transform for each pointcloud.\n        spatial_transforms = [transform_subnet(i, [64, 128, 256], [256, 64]) for i in inputs]\n        inputs_tr = [apply_transform_layer(i, tr, self.pt_dim) for i, tr in zip(inputs, spatial_transforms)]\n    else:\n        inputs_tr = inputs\n\n    global_feats = []\n    for i, input_pts in enumerate(inputs_tr):\n       x = input_pts\n\n       # Convolution stack\n       for j, c in enumerate(conv_filter_counts):\n           x = Convolution1D(c, 1, activation='relu', name='conv1d_{}_{}'.format(i, j))(x)\n           x = BatchNormalization(name='batchnorm_{}_{}'.format(i, j))(x)\n\n       global_feats += [GlobalMaxPooling1D(name='global_max_{}'.format(i))(x)]\n\n    # Concatenate features and possibly auxiliary input\n    if self.aux_input_count > 0:\n        x = aux_input\n\n        # Create a dense subnetwork just for the auxiliary inpuy\n        for i, (c, d) in enumerate(zip(dense_counts, dense_dropout_rates)):\n            x = Dense(c, activation='relu', name='aux_dense_{}'.format(i))(x)\n\n        x = Concatenate()(global_feats + [x])\n    elif len(global_feats) > 1:\n        x = Concatenate()(global_feats)\n    else:\n        x = global_feats[0]\n\n    # Dense stack with optional dropout\n    if dense_dropout_rates is None:\n        dense_dropout_rates = [None] * len(dense_counts)\n\n    for i, (c, d) in enumerate(zip(dense_counts, dense_dropout_rates)):\n        x = Dense(c, activation='relu', name='dense_{}'.format(i))(x)\n        if d is not None:\n            x = Dropout(rate=d, name='dropout_{}'.format(i))(x)\n\n    # Final prediction\n    prediction = Dense(self.class_count, activation='softmax', name='prediction')(x)\n\n    # Link all up in a model\n    if self.aux_input_count > 0:\n        inputs.append(aux_input)\n\n    if len(inputs) == 1:\n        inputs = inputs[0]\n\n    return Model(inputs=inputs, outputs=prediction)\n<\/code><\/pre>\n\n

Kind regards,<\/p>\n\n

steven<\/p>\n","answers":[{"AnswerId":"52984880","CreationDate":"2018-10-25T08:37:17.550","ParentId":null,"OwnerUserId":"785041","Title":null,"Body":"

A cautious answer to my own question, @Mike, I think (hope?) this is indeed a bug on the tensorboard side as I can't explain it otherwise. <\/p>\n\n

I plotted the architecture using keras.utils.plot_model<\/code> and this also doesn't show any links between the BatchNormalization layers.<\/p>\n"}]} +{"QuestionId":52587151,"AnswerCount":0,"Tags":"","CreationDate":"2018-10-01T08:24:03.867","AcceptedAnswerId":null,"OwnerUserId":10439898.0,"Title":"tensorflow - how to input a directory by dataset api","Body":"

I am new to tensorflow, and here is my situation: I have lots of folders and each contains several images. I need my training input to be folders(each time 2 folders), and each time 4 images inside a folder be selected for training.\nI have tried Dataset api, and tried to use the map<\/code> or flat_map<\/code> function, but I failed to read images inside a folder.\nHere is part of my codes:<\/p>\n\n

def parse_function(filename):\n    print(filename)\n    batch_data = []\n    batch_label = []\n    dir_path = os.path.join(data_path, str(filename))\n    imgs_list = os.listdir(dir_path)\n    random.shuffle(imgs_list)\n    imgs_list = imgs_list * 4 #each time select 4 images\n    for i in range(img_num):\n        img_path = os.path.join(dir_path, imgs_list[i])\n        image_string = tf.read_file(img_path)  \n        image_decoded = tf.image.decode_image(image_string)  \n        image_resized = tf.image.resize_images(image_decoded, [224, 224])\n        batch_data.append(image_resized)\n        batch_label.append(label)\n    return batch_data, batch_label\ndataset = tf.data.Dataset.from_tensor_slices((filenames, labels)) \ndataset = dataset.map(_parse_function) \n<\/code><\/pre>\n\n

where filename is a list of folder name like '123456', labels is list of label like 0 or 1.<\/p>\n","answers":[]} +{"QuestionId":52587227,"AnswerCount":1,"Tags":"","CreationDate":"2018-10-01T08:29:47.663","AcceptedAnswerId":null,"OwnerUserId":9900971.0,"Title":"how to install pytorch version 0.1.12 in anaconda 3.6 windows 10?","Body":"

Tried to install with this command but still didn't work-> conda install -c peterjc123 pytorch=0.1.12<\/p>\n\n

Also tried installing using this command:\nconda install pytorch=0.1.12 -c pytorch\nHow can it be installed with python anaconda 3.6?<\/p>\n","answers":[{"AnswerId":"52588937","CreationDate":"2018-10-01T10:14:33.370","ParentId":null,"OwnerUserId":"6390175","Title":null,"Body":"

First of all, make sure that Python 3.5 or later<\/code> is installed as well.<\/p>\n\n