コード例 #1
0
def _GetCaptchaIdsFromImageFilename(image_filepath):
  captcha_str = _ParseCaptchaFromImageFilename(image_filepath)
  captcha_ids = numpy.zeros(len(captcha_str), dtype=numpy.int32)
  for i, captcha_char in enumerate(captcha_str):
    CHAR_VOCABULARY, CHARS = vocabulary.GetCharacterVocabulary(sys.argv[2])    
    captcha_ids[i] = CHAR_VOCABULARY[captcha_char]
  return captcha_ids
コード例 #2
0
ファイル: nn_model.py プロジェクト: watermars/Captcha-Decoder
    def __init__(self,
                 learning_rate=0.01,
                 no_hidden_layers=2,
                 includeCapital=False,
                 num_rnn_steps=5,
                 saved_params_path=None,
                 multi_chars=True,
                 num_softmaxes=None,
                 use_mask_input=False,
                 lstm_layer_units=256,
                 cnn_dense_layer_sizes=[256],
                 bidirec=False,
                 lstm_grad_clipping=False):

        if not learning_rate:
            self.learning_rate = 0.01
        else:
            self.learning_rate = float(learning_rate)
        if not no_hidden_layers:
            self.no_hidden_layers = 2
        else:
            self.no_hidden_layers = int(no_hidden_layers)
        self.num_rnn_steps = num_rnn_steps
        self.includeCapital = includeCapital
        self.CHAR_VOCABULARY, self.CHARS = vocabulary.GetCharacterVocabulary(
            includeCapital)
        if multi_chars:
            if num_softmaxes:
                self._network, self._train_fn, self._test_fn, self._inference_fn = (
                    self._InitializeModelThatPredictsCharsMultiSoftmax(
                        self.learning_rate, num_softmaxes=num_softmaxes))
            else:
                self._network, self._train_fn, self._test_fn, self._inference_fn = (
                    self._InitializeModelThatPredictsAllChars(
                        self.learning_rate,
                        use_mask_input=use_mask_input,
                        lstm_layer_units=lstm_layer_units,
                        cnn_dense_layer_sizes=cnn_dense_layer_sizes,
                        bidirectional_rnn=bidirec,
                        lstm_grad_clipping=lstm_grad_clipping))
        else:
            self._network, self._train_fn, self._test_fn, self._inference_fn = (
                self._InitializeModelThatPredictsFirstChar(self.learning_rate))
        self.prediction = lasagne.layers.get_output(self._network)
        if saved_params_path:
            ''' 
      If saved params path is specified, then start from that parms value.
      '''
            f = numpy.load(saved_params_path)
            param_values = [f['arr_%d' % i] for i in range(len(f.files))]
            '''
      Deleting a vector as it is not needed. It was taking memory. so needed to delete it explicitly.
      '''
            del f.f
            f.close()
            lasagne.layers.set_all_param_values(self._network, param_values)