예제 #1
0
	  '            you should not pass\n',
	  '            non picklable arguments to the generator\n',
	  "            as they can't be passed\n",
	  '            easily to children processes.\n',
	  '        verbose: verbosity mode, 0 or 1.\n',
	  '\n',
	  '    Returns:\n',
	  '        Numpy array(s) of predictions.\n',
	  '\n',
	  '    Raises:\n',
	  '        ValueError: In case the generator yields\n',
	  '            data in an invalid format.\n',
	"""

	preds_batch = model.predict_on_batch(val_img_array)

	"""
	(['  def predict_on_batch(self, x):\n',
	  '    Returns predictions for a single batch of samples.\n',
	  '\n',
	  '    Arguments:\n',
	  '        x: Input samples, as a Numpy array.\n',
	  '\n',
	  '    Returns:\n',
	  '        Numpy array(s) of predictions.\n',
	"""


# how weights of model are saved
model.save_weights("/Users/Natsume/Downloads/data_for_all/dogscats/experiments/weights.h5")
예제 #2
0
                dprint('Loss Classifier classifier: {}'.format(
                    (loss_class_cls)))
                dprint('Loss Classifier regression: {}'.format(
                    (loss_class_regr)))
                dprint('Elapsed time: {}'.format(time.time() - start_time))
            else:
                dprint(
                    'loss_rpn_cls,{},loss_rpn_regr,{},loss_class_cls,{},loss_class_regr,{},class_acc,{},elapsed_time,{}'
                    .format(loss_rpn_cls, loss_rpn_regr, loss_class_cls,
                            loss_class_regr, class_acc,
                            time.time() - start_time))
            curr_loss = loss_rpn_cls + loss_rpn_regr + loss_class_cls + loss_class_regr
            iter_num = 0
            start_time = time.time()
            epoch_num += 1
            if epoch_num == 1 or curr_loss < best_loss:
                if C.verbose:
                    dprint(
                        'Total loss decreased from {} to {}, saving weights'.
                        format(best_loss, curr_loss))
                best_loss = curr_loss
                model_all.save_weights(C.model_path)
        if epoch_num == num_epochs:
            dprint('Training complete, exiting.')
            sys.exit()
    except Exception as e:
        dprint('Exception: %s' % (e))
        continue

K.clear_session()
You can then build a fresh model from this data:
"""

# model reconstruction from JSON:
model_json = model_from_json(json_string)

# model reconstruction from YAML
model_yaml = model_from_yaml(yaml_string)
"""
If you need to save the **weights of a model**, you can do so in HDF5 with the code below.

Note that you will first need to install HDF5 and the Python library h5py, which do not come bundled with Keras.
"""

model.save_weights('to_delete_weights.h5')
"""
Assuming you have code for instantiating your model, you can then load the weights you saved into a model with the *same* architecture:
"""

model_json.load_weights('to_delete_weights.h5')
"""
If you need to load weights into a *different* architecture (with some layers in common), for instance for fine-tuning or transfer-learning, you can load weights by *layer name*:
"""
model_yaml.load_weights('to_delete_weights.h5', by_name=True)

# make sure they share the same weights: total 202 parameters
(model_json.get_weights()[0] == model_yaml.get_weights()[0]).sum()
(model_json.get_weights()[1] == model_yaml.get_weights()[1]).sum()
"""
For example