sorenbouma / keras-oneshot

koch et al, Siamese Networks for one-shot learning, (mostly) reimplimented in keras
MIT License
373 stars 174 forks source link

When I was training data, I changed the value of evaluate_every to 100, and the original value was 500. However, there are the following errors. Can you help me solve this problem again? Thank you very much for your help. #9

Open H0203 opened 6 years ago

H0203 commented 6 years ago

When I was training data, I changed the value of evaluate_every to 100, and the original value was 500. However, there are the following errors. Can you help me solve this problem again? Thank you very much for your help.

errors: iteration 50, training loss: 6.15, Evaluating model on 250 unique 20 way one-shot learning tasks ...

UnboundLocalError Traceback (most recent call last)

in () 11 12 if i % evaluate_every == 0: ---> 13 val_acc = loader.test_oneshot(siamese_net,N_way,n_val,verbose=True) 14 print('val_acc的值为:' + val_acc) 15 if val_acc >= best: in test_oneshot(self, model, N, k, s, verbose) 67 print("Evaluating model on {} unique {} way one-shot learning tasks ...".format(k,N)) 68 for i in range(k): ---> 69 inputs, targets = self.make_oneshot_task(N,s) 70 probs = model.predict(inputs) 71 if np.argmax(probs) == np.argmax(targets): in make_oneshot_task(self, N, s, language) 51 ex1, ex2 = rng.choice(n_examples,replace=False,size=(2,)) 52 test_image = np.asarray([X[true_category,ex1,:,:]]*N).reshape(N,self.w,self.h,1) ---> 53 support_set = X[categories,indices,:,:] 54 support_set[0,:,:] = X[true_category,ex2] 55 support_set = support_set.reshape(N,self.w,self.h,1) UnboundLocalError: local variable 'indices' referenced before assignment
H0203 commented 6 years ago

This problem can be solved by adding a new code “ global indices” in front of the code of the “indices = rng.randint(0,self.n_examples,size=(N,))” sentence.