Mercurial > ift6266
comparison deep/stacked_dae/v_sylvain/sgd_optimization.py @ 361:b599886e3655
Ajout d'une fonctionnalite utile avec le programme voir_erreurs.py afin de voir les exemples ainsi que la prediction du modele donne dans le fichier config.py
author | SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca> |
---|---|
date | Thu, 22 Apr 2010 13:17:19 -0400 |
parents | cfb79f9fd1a4 |
children | f24b10e43a6f |
comparison
equal
deleted
inserted
replaced
360:f37c0705649d | 361:b599886e3655 |
---|---|
375 | 375 |
376 iter2 = dataset.train(self.hp.minibatch_size,bufsize=buffersize) | 376 iter2 = dataset.train(self.hp.minibatch_size,bufsize=buffersize) |
377 train_losses2 = [test_model(x,y) for x,y in iter2] | 377 train_losses2 = [test_model(x,y) for x,y in iter2] |
378 train_score2 = numpy.mean(train_losses2) | 378 train_score2 = numpy.mean(train_losses2) |
379 print "Training error is: " + str(train_score2) | 379 print "Training error is: " + str(train_score2) |
380 | 380 |
381 | 381 #To see the prediction of the model, the real answer and the image to judge |
382 | 382 def see_error(self, dataset): |
383 | 383 import pylab |
384 #The function to know the prediction | |
385 test_model = \ | |
386 theano.function( | |
387 [self.classifier.x,self.classifier.y], self.classifier.logLayer.y_pred) | |
388 user = [] | |
389 nb_total = 0 #total number of exemples seen | |
390 nb_error = 0 #total number of errors | |
391 for x,y in dataset.test(1): | |
392 nb_total += 1 | |
393 pred = self.translate(test_model(x,y)) | |
394 rep = self.translate(y) | |
395 error = pred != rep | |
396 print 'prediction: ' + str(pred) +'\t answer: ' + str(rep) + '\t right: ' + str(not(error)) | |
397 pylab.imshow(x.reshape((32,32))) | |
398 pylab.draw() | |
399 if error: | |
400 nb_error += 1 | |
401 user.append(int(raw_input("1 = The error is normal, 0 = The error is not normal : "))) | |
402 print '\t\t character is hard to distinguish: ' + str(user[-1]) | |
403 else: | |
404 time.sleep(3) | |
405 print '\n Over the '+str(nb_total)+' exemples, there is '+str(nb_error)+' errors. \nThe percentage of errors is'+ str(float(nb_error)/float(nb_total)) | |
406 print 'The percentage of errors done by the model that an human will also do: ' + str(numpy.mean(user)) | |
407 | |
408 | |
409 | |
410 | |
411 #To translate the numeric prediction in character if necessary | |
412 def translate(self,y): | |
413 | |
414 if y <= 9: | |
415 return y[0] | |
416 elif y == 10: | |
417 return 'A' | |
418 elif y == 11: | |
419 return 'B' | |
420 elif y == 12: | |
421 return 'C' | |
422 elif y == 13: | |
423 return 'D' | |
424 elif y == 14: | |
425 return 'E' | |
426 elif y == 15: | |
427 return 'F' | |
428 elif y == 16: | |
429 return 'G' | |
430 elif y == 17: | |
431 return 'H' | |
432 elif y == 18: | |
433 return 'I' | |
434 elif y == 19: | |
435 return 'J' | |
436 elif y == 20: | |
437 return 'K' | |
438 elif y == 21: | |
439 return 'L' | |
440 elif y == 22: | |
441 return 'M' | |
442 elif y == 23: | |
443 return 'N' | |
444 elif y == 24: | |
445 return 'O' | |
446 elif y == 25: | |
447 return 'P' | |
448 elif y == 26: | |
449 return 'Q' | |
450 elif y == 27: | |
451 return 'R' | |
452 elif y == 28: | |
453 return 'S' | |
454 elif y == 28: | |
455 return 'T' | |
456 elif y == 30: | |
457 return 'U' | |
458 elif y == 31: | |
459 return 'V' | |
460 elif y == 32: | |
461 return 'W' | |
462 elif y == 33: | |
463 return 'X' | |
464 elif y == 34: | |
465 return 'Y' | |
466 elif y == 35: | |
467 return 'Z' | |
468 | |
469 elif y == 36: | |
470 return 'a' | |
471 elif y == 37: | |
472 return 'b' | |
473 elif y == 38: | |
474 return 'c' | |
475 elif y == 39: | |
476 return 'd' | |
477 elif y == 40: | |
478 return 'e' | |
479 elif y == 41: | |
480 return 'f' | |
481 elif y == 42: | |
482 return 'g' | |
483 elif y == 43: | |
484 return 'h' | |
485 elif y == 44: | |
486 return 'i' | |
487 elif y == 45: | |
488 return 'j' | |
489 elif y == 46: | |
490 return 'k' | |
491 elif y == 47: | |
492 return 'l' | |
493 elif y == 48: | |
494 return 'm' | |
495 elif y == 49: | |
496 return 'n' | |
497 elif y == 50: | |
498 return 'o' | |
499 elif y == 51: | |
500 return 'p' | |
501 elif y == 52: | |
502 return 'q' | |
503 elif y == 53: | |
504 return 'r' | |
505 elif y == 54: | |
506 return 's' | |
507 elif y == 55: | |
508 return 't' | |
509 elif y == 56: | |
510 return 'u' | |
511 elif y == 57: | |
512 return 'v' | |
513 elif y == 58: | |
514 return 'w' | |
515 elif y == 59: | |
516 return 'x' | |
517 elif y == 60: | |
518 return 'y' | |
519 elif y == 61: | |
520 return 'z' | |
521 | |
522 | |
523 | |
524 |