{"action":"created","issue":{"url":"https://api.github.com/repos/shamangary/Keras-MNIST-center-loss-with-visualization/issues/3","repository_url":"https://api.github.com/repos/shamangary/Keras-MNIST-center-loss-with-visualization","labels_url":"https://api.github.com/repos/shamangary/Keras-MNIST-center-loss-with-visualization/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/shamangary/Keras-MNIST-center-loss-with-visualization/issues/3/comments","events_url":"https://api.github.com/repos/shamangary/Keras-MNIST-center-loss-with-visualization/issues/3/events","html_url":"https://github.com/shamangary/Keras-MNIST-center-loss-with-visualization/issues/3","id":326867619,"number":3,"title":"验证集的准确率不提高？","user":{"login":"alyato","id":6815071,"avatar_url":"https://avatars3.githubusercontent.com/u/6815071?v=4","gravatar_id":"","url":"https://api.github.com/users/alyato","html_url":"https://github.com/alyato","followers_url":"https://api.github.com/users/alyato/followers","following_url":"https://api.github.com/users/alyato/following{/other_user}","gists_url":"https://api.github.com/users/alyato/gists{/gist_id}","starred_url":"https://api.github.com/users/alyato/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alyato/subscriptions","organizations_url":"https://api.github.com/users/alyato/orgs","repos_url":"https://api.github.com/users/alyato/repos","events_url":"https://api.github.com/users/alyato/events{/privacy}","received_events_url":"https://api.github.com/users/alyato/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-05-28T01:07:37Z","updated_at":"2018-05-29T15:04:02Z","closed_at":null,"author_association":"NONE","body":"hi @shamangary \r\n我用我自己的数据集，训练。在测试集上的结果很差，只有14%，而且发现dense_2_acc 不提高，最高到19%。如果，我不用center_loss,在测试集上的准确率有50%。\r\n![2018-05-27 6 14 57](https://user-images.githubusercontent.com/6815071/40592523-0fdd8066-6253-11e8-8050-be13e5943f6d.png)\r\n加载数据集\r\n\r\n> 训练集和验证集\r\ntrain,trainlabel = xrp.loadtrain(）\r\n    train = densenet.preprocess_input(train)\r\n     index = [i for i in range(len(train))]\r\n      random.shuffle(index)\r\n      train = train[index]\r\n     trainlabel = trainlabel[index]\r\n      (x_train,x_test)=(train[0:11000],train[11000:])\r\n      (y_train,y_test)=(trainlabel[0:11000],trainlabel[11000:])\r\n      y_train_value = y_train\r\n      y_test_value = y_test\r\n      y_train = np_utils.to_categorical(y_train,nb_classes)\r\n      y_test = np_utils.to_categorical(y_test,nb_classes)\r\n测试集\r\nX_test,Y_test = xrp.loadtest()\r\n     Z_test_value = Y_test\r\n     Y_test = np_utils.to_categorical(Y_test,nb_classes)\r\n     X_test = densenet.preprocess_input(X_test)\r\n\r\n> 网络结构如下\r\nbase_model = VGG16(weights='imagenet',include_top=False)\r\n    x = base_model.output\r\n     x = GlobalAveragePooling2D()(x)\r\n     x = BatchNormalization(axis=1)(x)\r\n     ip1 = Dense(1024,activation='relu')(x)\r\n      predictions = Dense(8,activation='softmax')(ip1)\r\n     model = Model(input=base_model.input,output=predictions)\r\n\r\n     for layer in base_model.layers:\r\n          layer.trainable = True\r\n \r\n     sgd = SGD(lr=0.0001, decay=1e-6, momentum=0.9,nesterov=True)\r\n     model.compile(optimizer='rmsprop',loss='categorical_crossentropy')\r\n  #this is the center_loss\r\nisCenterloss = True\r\n\r\n      if isCenterloss:\r\n          lambda_c = 0.2\r\n          input_target = Input(shape=(1,))\r\n          centers = Embedding(8,1024)(input_target)\r\n          l2_loss = Lambda(lambda x: K.sum(K.square(x[0]- \r\n          x[1[:,0]),1,keepdims=True),name='l2_loss')\r\n          model_centerloss = Model(inputs=[base_model.input,input_target],outputs=[predictions,l2_loss])\r\n         sgd_1 = SGD(lr=0.00001, decay=1e-6, momentum=0.9,nesterov=True)\r\n          model_centerloss.compile(optimizer=sgd_1, loss=[\"categorical_crossentropy\", lambda y_true,,y_pred: y_pred],loss_weights=[1,lambda_c],metrics=['accuracy'])\r\n \r\n      if isCenterloss:\r\n         random_y_train = np.random.rand(x_train.shape[0],1)\r\n         random_y_test = np.random.rand(x_test.shape[0],1)\r\n         model_centerloss.fit([x_train,y_train_value], [y_train, random_y_train], batch_size=batch_size,epochs=nb_epoch, verbose=1, validation_data=([x_test,y_test_value], [y_test,random_y_test]))\r\n\r\n预测代码如下：\r\n\r\n> privateLabel_0\r\n= model_centerloss.predict([X_test,Z_test_value],batch_size=1,verbose=1)    print (len(privateLabel_0)\r\n    privateLabel = privateLabel_0[0]\r\n     list_label1 = []\r\n     list_label2 = []\r\n    x= len(privateLabel)\r\n\r\n    for j in range(x):\r\n         list_label1.append(np.argmax(Y_test[j]))\r\n         list_label2.append(np.argmax(privateLabel[j]))\r\n\r\n> privateAcc\r\n= len([1 for i in range(len(Y_test)) if list_label2[i]==list_label1[i]])/float(len(Y_test))\r\nprint ('the privateAcc is ',privateAcc)\r\n\r\n我调整了learning_rate = 0.00001,可是效果不好，dense_2_acc 不提高。\r\n请问一下，是哪方面的问题。谢谢。"},"comment":{"url":"https://api.github.com/repos/shamangary/Keras-MNIST-center-loss-with-visualization/issues/comments/392810695","html_url":"https://github.com/shamangary/Keras-MNIST-center-loss-with-visualization/issues/3#issuecomment-392810695","issue_url":"https://api.github.com/repos/shamangary/Keras-MNIST-center-loss-with-visualization/issues/3","id":392810695,"user":{"login":"shamangary","id":12425585,"avatar_url":"https://avatars0.githubusercontent.com/u/12425585?v=4","gravatar_id":"","url":"https://api.github.com/users/shamangary","html_url":"https://github.com/shamangary","followers_url":"https://api.github.com/users/shamangary/followers","following_url":"https://api.github.com/users/shamangary/following{/other_user}","gists_url":"https://api.github.com/users/shamangary/gists{/gist_id}","starred_url":"https://api.github.com/users/shamangary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shamangary/subscriptions","organizations_url":"https://api.github.com/users/shamangary/orgs","repos_url":"https://api.github.com/users/shamangary/repos","events_url":"https://api.github.com/users/shamangary/events{/privacy}","received_events_url":"https://api.github.com/users/shamangary/received_events","type":"User","site_admin":false},"created_at":"2018-05-29T15:04:02Z","updated_at":"2018-05-29T15:04:02Z","author_association":"OWNER","body":"由於Embedding吃的是單一值的label而不是one-hot的label所以@alyato講的是對的喔\r\n\r\nhttps://github.com/keras-team/keras/issues/4981\r\n這裡有討論如何把one-hot變成單一值，使用np.argmax or K.argmax皆可"}}
{"actor":{"display_login":"shamangary"}}