Giter VIP home page Giter VIP logo

referringrelationships's Introduction

Referring Relationships

Referring Relationships model

This repository contains code used to produce the results in the following paper:

Ranjay Krishna, Ines Chami, Michael Bernstein, Li Fei-Fei
IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2018

If you are using this repository, please use the following citation:

@inproceedings{krishna2018referring,
  title={Referring Relationships},
  author={Krishna, Ranjay and Chami, Ines and Bernstein, Michael and Fei-Fei, Li },
  booktitle={IEEE Conference on Computer Vision and Pattern Recognition},
  year={2018}
}

Clone the repository and install the dependencies.

You can clone the repository and install the requirements by running the following:

git clone https://github.com/stanfordvl/ReferringRelationships.git
cd ReferringRelationships
virtualenv -p python3 env
source env/bin/activate
pip install -r requirements.txt

To download the dataset used in the project, run:

./scripts/download_data.sh

Note that we only distribute the annotations for the datasets. To download the images for these datasets, please use the following links:

Model training

To train the models, you will need to create an hdf5 dataset and then run the following script to test and evaluate the model:

# For the VRD dataset.
./scripts/create_vrd_dataset.sh $LOCATION_OF_VRD_TRAIN_IMAGES $LOCATION_OF_VRD_TEST_IMAGES
./scripts/train_vrd.sh
./scripts/evaluate_vrd.sh
# For the CLEVR dataset.
./scripts/create_clevr_dataset.sh $LOCATION_OF_CLEVR_TRAIN_IMAGES $LOCATION_OF_CLEVR_VAL_IMAGES
./scripts/train_clevr.sh $LOCATION_OF_MODEL
./scripts/evaluate_clevr.sh $LOCATION_OF_MODEL
# For the Visual Genome dataset.
./scripts/create_visualgenome_dataset.sh $LOCATION_OF_VISUAL_GENOME_IMAGES
./scripts/train_visualgenome.sh $LOCATION_OF_MODEL
./scripts/evaluate_visualgenome.sh $LOCATION_OF_MODEL

This script will train the model and save the weights in the --save-dir directory. It will also save the configuration parameters in a params.json file and log events in train.log.

However, if you decide that you want more control over the training or evaluation scripts, check out the instructions below.

Customized dataset creation

The script data.py will save masks for objects and subjects in train/val/test directories that will be created in the directory --save-dir. The script also saves numpy arrays for relationships.

The script has the following command line arguments to modify the dataset pre-processing:

  -h, --help            show this help message and exit
  --test                When true, the data is not split into training and
                        validation sets
  --val-percent         Fraction of images in validation split.
  --save-dir            where to save the ground truth masks, this Location
                        where dataset should be saved.
  --img-dir             Location where images are stored.
  --annotations         Json with relationships for each image.
  --image-metadata      Image metadata json file.
  --image-dim           The size the images should be saved as.
  --output-dim          The size the predictions should be saved as.
  --seed                The random seed used to reproduce results.
  --num-images          The random seed used to reproduce results.
  --save-images         Use this flag to specify that the images should also
                        be saved.
  --max-rels-per-image  Maximum number of relationships per image.

Customized Training.

The model can be trained by calling python train.py with the following command line arguments to modify your training:

optional arguments:
  -h, --help            Show this help message and exit
  --opt                 The optimizer used during training. Currently supports
                        rms, adam, adagrad and adadelta.
  --lr                  The learning rate for training.
  --lr_decay            The learning rate decay.
  --batch-size          The batch size used in training.
  --epochs              The number of epochs to train.
  --seed                The random seed used to reproduce results.
  --overwrite           Train even if that folder already contains an existing
                        model.
  --save-dir            The location to save the model and the results.
  --models-dir          The location of the model weights
  --use-models-dir      Indicates that new models can be saved in the models
                        directory set by --models-dir.
  --save-best-only      Saves only the best model checkpoint.

  --use-subject         Boolean indicating whether to use the subjects.
  --use-predicate       Boolean indicating whether to use the predicates.
  --use-object          Boolean indicating whether to use the objects.

  --embedding-dim       Number of dimensions in our class embeddings.
  --hidden-dim          Number of dimensions in the hidden unit.
  --feat-map-dim        The size of the feature map extracted from the image.
  --input-dim           Size of the input image.
  --num-predicates      The number of predicates in the dataset.
  --num-objects         The number of objects in the dataset.
  --dropout             The dropout probability used in training.

  --train-data-dir      Location of the training data.
  --val-data-dir        Location of the validation data.
  --image-data-dir      Location of the images.
  --heatmap-threshold   The thresholds above which we consider a heatmap to
                        contain an object.

Customized evaluation

The evaluations can be run using python evaluate.py with the following options:

  -h, --help            show this help message and exit
  --batch-size          The batch size used in training.
  --seed                The random seed used to reproduce results.
  --workers             Number workers used to load the data.
  --heatmap-threshold   The thresholds above which we consider a heatmap to
                        contain an object.
  --model-checkpoint    The model to evaluate.
  --data-dir            Location of the data to evluate with.

Customized discovery evaluation.

The discovery based experiments can be run by setting the following flags during training and using python evaluate_discovery.py when evaluating.

  --discovery           Used when we run the discovery experinent where
                        objects are dropped during training.
  --always-drop-file    Location of list of objects that should always be
                        dropped.
  --subject-droprate    Rate at which subjects are dropped.
  --object-droprate     Rate at which objects are dropped.
  --model-checkpoint    The model to evaluate.
  --data-dir            Location of the data to evluate with.

Contributing.

We welcome everyone to contribute to this reporsitory. Send us a pull request.

License:

The code is under the MIT license. Check LICENSE for details.

referringrelationships's People

Contributors

jaesuny avatar ranjaykrishna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

referringrelationships's Issues

When train on VRD, errors about configs.

I've downloaded the VRD dataset and converted it to hdf5 pattern.
Then I came to the second step
./scripts/train_vrd.sh
But the terminal shown :
train.py: error: argument --save-dir: expected one argument
Then I input:
./scripts/train_vrd.sh --save-dir=/home/yyf/ReferringRelationships/output/train_vrd
The error remained.
How could I handle it? Thanks.

Something wrong in training Clevr

It is a really impressive work, however I meet the following problem, it seems that there is something with the size, but I just follow the README.
nohup ./scripts/train_clevr.sh /home/hjz/hjzfolder/ReferringRelationships-master/checkpoints &

return self.build_ssas()
File "/home/hjz/hjzfolder/ReferringRelationships-master/models.py", line 130, in build_ssas
new_image_features = Multiply()([im_features, predicate_att])
File "/home/hjz/anaconda3/envs/tf-keras/lib/python3.6/site-packages/keras/engine/topology.py", line 571, in call
self.build(input_shapes)
File "/home/hjz/anaconda3/envs/tf-keras/lib/python3.6/site-packages/keras/layers/merge.py", line 84, in build
output_shape = self._compute_elemwise_op_output_shape(output_shape, shape)
File "/home/hjz/anaconda3/envs/tf-keras/lib/python3.6/site-packages/keras/layers/merge.py", line 55, in _compute_elemwise_op_output_shape
str(shape1) + ' ' + str(shape2))
ValueError: Operands could not be broadcast together with shapes (14, 14, 1024) (14, 14, 6)

Some questions about visualization.ipynb in drawing bounding box.

I'm wondering how the model could draw the bounding box on the input image.

The image was first resize to 224x224, then after the convolutions, 14x14 feature map could be abtained.

The bounding box's coordinates range from [0,13] rather than the [0,223].

How could I obtain a result with the bounding box drawn in it?

I've tried interpolation='spline16' but it didn't work well.

Thanks!!!!~~~ :)

Some questions about the order of subject, predicate, object in VRD dataset.

I'm wondering how the annotations were done in VRD dataset.

The "category": 0 for subject or object means that the entity is a person?
And the sequence just goes down as the Table 4 in the paper?
So could I infer that "category": 1 for truck and "category": 2 for shirt ?

Is it the same implication that the Table 3 for the predicate goes in the same way?

VRD dataset

Where we can find the image of VRD dataset?

How to achieve visualization?

I've trained on VRD dataset and obtained the corresponding model.h5 file .
Given the input test image, how could I visualize and get the output with bounding box in subject and object?
Thanks!!!!~:)

Could not obtain images.hdf5

I've completely finished the experiment on VRD dataset.
After the conversion, I obtained images.hdf5 and dataset.hdf5.

But when converting the CLEVR dataset into *.hdf5 pattern,
I could only obtain dataset.hdf5 without images.hdf5.

Besides, I found there's create_small_clevr_dataset.sh and it works.
Using the create_small_clevr_dataset.sh, I could obtain both images.hdf5 and datset.hdf5.
With the data converted by create_small_clevr_dataset.sh, would the result be affected?

Could please give me some suggestions?
Thanks!

Inference from the saved model

Based on the issue, I was able to save a model in pb format as well we previously saved a model in h5 format (Keras model).
I am trying to serve a model using TensorFlow servings, but the saved model doesn't have the signature definition, and hence couldn't do inference from the client.

Is there other way to do inference?

saved_model_cli show --dir /home/dsdev/gitrepo/ReferringRelationships/model/1/ --all
MetaGraphDef with tag-set: '' contains the following SignatureDefs:
Traceback (most recent call last):
  File "/data/anaconda/envs/py35/bin/saved_model_cli", line 11, in <module>
    sys.exit(main())
  File "/data/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/tools/saved_model_cli.py", line 910, in main
    args.func(args)
  File "/data/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/tools/saved_model_cli.py", line 611, in show
    _show_all(args.dir)
  File "/data/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/tools/saved_model_cli.py", line 199, in _show_all
    signature_def_map = get_signature_def_map(saved_model_dir, tag_set)
  File "/data/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/tools/saved_model_cli.py", line 243, in get_signature_def_map
    meta_graph = saved_model_utils.get_meta_graph_def(saved_model_dir, tag_set)
  File "/data/anaconda/envs/py35/lib/python3.5/site-packages/tensorflow/python/tools/saved_model_utils.py", line 49, in get_meta_graph_def
    ' could not be found in SavedModel')
RuntimeError: MetaGraphDef associated with tag-set  could not be found in SavedModel

and

dsdev@dsdev:/mnt/data/dataset-visualgenome/train$ tensorflow_model_server --port=8500 --rest_api_port=8501 --model_name=refrel --model_base_path=/home/dsdev/gitrepo/ReferringRelationships/model/
2019-11-12 07:09:14.359747: I tensorflow_serving/model_servers/server.cc:82] Building single TensorFlow model file config:  model_name: refrel model_base_path: /home/dsdev/gitrepo/ReferringRelationships/model/
2019-11-12 07:09:14.359974: I tensorflow_serving/model_servers/server_core.cc:461] Adding/updating models.
2019-11-12 07:09:14.359995: I tensorflow_serving/model_servers/server_core.cc:558]  (Re-)adding model: refrel
2019-11-12 07:09:14.460213: I tensorflow_serving/core/basic_manager.cc:739] Successfully reserved resources to load servable {name: refrel version: 1}
2019-11-12 07:09:14.460243: I tensorflow_serving/core/loader_harness.cc:66] Approving load for servable version {name: refrel version: 1}
2019-11-12 07:09:14.460261: I tensorflow_serving/core/loader_harness.cc:74] Loading servable version {name: refrel version: 1}
2019-11-12 07:09:14.460283: I external/org_tensorflow/tensorflow/contrib/session_bundle/bundle_shim.cc:363] Attempting to load native SavedModelBundle in bundle-shim from: /home/dsdev/gitrepo/ReferringRelationships/model/1
2019-11-12 07:09:14.460298: I external/org_tensorflow/tensorflow/cc/saved_model/reader.cc:31] Reading SavedModel from: /home/dsdev/gitrepo/ReferringRelationships/model/1
2019-11-12 07:09:14.533650: I external/org_tensorflow/tensorflow/cc/saved_model/reader.cc:54] Reading meta graph with tags { serve }
2019-11-12 07:09:14.538127: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:259] SavedModel load for tags { serve }; Status: fail. Took 77816 microseconds.
2019-11-12 07:09:14.538160: E tensorflow_serving/util/retrier.cc:37] Loading servable: {name: refrel version: 1} failed: Not found: Could not find meta graph def matching supplied tags: { serve }. To inspect available tag-sets in the SavedModel, please use the SavedModel CLI: `saved_model_cli`

About the VRD dataset

Where can I download the VRD dataset's images???
I notice that there are only annotations for the VRD dataset where I can download.

IndexError: list index out of range

I read the 'requirements.txt' the ensured that mine was equipped equally as it.
When I started to train on VRD, I met the problem.
The log follows:
Traceback (most recent call last): File "train.py", line 70, in <module> model = relationships_model.build_model() File "/home/yyf/ReferringRelationships/models.py", line 75, in build_model return self.build_ssas() File "/home/yyf/ReferringRelationships/models.py", line 154, in build_ssas subject_att = Concatenate(axis=3)(subject_outputs) File "/home/yyf/ReferringRelationships/env/lib/python3.6/site-packages/keras/engine/topology.py", line 583, in __call__ previous_mask = _collect_previous_mask(inputs) File "/home/yyf/ReferringRelationships/env/lib/python3.6/site-packages/keras/engine/topology.py", line 2752, in _collect_previous_mask mask = node.output_masks[tensor_index] IndexError: list index out of range

typo in pipeline diagram

2018-10-15 14 37 57

I think the diagram are wrong. It's easy to know the output of upper branch is object localization results.

Script to create bounding box annotations for CLEVR

Hello,

Thank you for making the code available.
I was wondering if you still have the script used to compute the bounding boxes from the CLEVR scene graph? According to Section 6.4 of the paper "We will release the conversion code as well as the bounding box annotations that we added to CLEVR."
I see the said annotations in the provided data but not the conversion script, unless I'm missing something?

I would like to apply the same conversion to other subsets of CLEVR.

Thanks in advance

Questions on visualization for VRD dataset

I was trying to visualize the trained result on VRD.
Having installed required packages and converting the visualization.ipynb into visualization.py, I ran the command python visualization.py but obtained result without attention-heatmap.

Besides, the "Final Heatmaps" I obtained just look like mosaic.

When it comes to "Final Bounding Boxes", error occured. And the log followed.
`Using TensorFlow backend.
person | sky | building | truck | bus | table | shirt | chair | car | train | glasses | tree | boat | hat | trees | grass | pants | road | motorcycle | jacket | monitor | wheel | umbrella | plate | bike | clock | bag | shoe | laptop | desk | cabinet | counter | bench | shoes | tower | bottle | helmet | stove | lamp | coat | bed | dog | mountain | horse | plane | roof | skateboard | traffic light | bush | phone | airplane | sofa | cup | sink | shelf | box | van | hand | shorts | post | jeans | cat | sunglasses | bowl | computer | pillow | pizza | basket | elephant | kite | sand | keyboard | plant | can | vase | refrigerator | cart | skis | pot | surfboard | paper | mouse | trash can | cone | camera | ball | bear | giraffe | tie | luggage | faucet | hydrant | snowboard | oven | engine | watch | face | street | ramp | suitcase

on | wear | has | next to | sleep next to | sit next to | stand next to | park next | walk next to | above | behind | stand behind | sit behind | park behind | in the front of | under | stand under | sit under | near | walk to | walk | walk past | in | below | beside | walk beside | over | hold | by | beneath | with | on the top of | on the left of | on the right of | sit on | ride | carry | look | stand on | use | at | attach to | cover | touch | watch | against | inside | adjacent to | across | contain | drive | drive on | taller than | eat | park on | lying on | pull | talk | lean on | fly | face | play with | sleep on | outside of | rest on | follow | hit | feed | kick | skate on
2019-07-21 18:58:26.328674: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-07-21 18:58:26.529961: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 0 with properties:
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:02:00.0
totalMemory: 10.92GiB freeMemory: 234.50MiB
2019-07-21 18:58:26.718689: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 1 with properties:
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:03:00.0
totalMemory: 10.92GiB freeMemory: 396.50MiB
2019-07-21 18:58:26.911887: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 2 with properties:
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:82:00.0
totalMemory: 10.92GiB freeMemory: 396.50MiB
2019-07-21 18:58:27.110755: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 3 with properties:
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
pciBusID: 0000:83:00.0
totalMemory: 10.92GiB freeMemory: 396.50MiB
2019-07-21 18:58:27.111219: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1227] Device peer to peer matrix
2019-07-21 18:58:27.111384: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1233] DMA: 0 1 2 3
2019-07-21 18:58:27.111410: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1243] 0: Y Y N N
2019-07-21 18:58:27.111420: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1243] 1: Y Y N N
2019-07-21 18:58:27.111429: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1243] 2: N N Y Y
2019-07-21 18:58:27.111437: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1243] 3: N N Y Y
2019-07-21 18:58:27.111454: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1312] Adding visible gpu devices: 0, 1, 2, 3
2019-07-21 18:58:28.672098: I tensorflow/core/common_runtime/gpu/gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 180 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0, compute capability: 6.1)
2019-07-21 18:58:28.673583: E tensorflow/stream_executor/cuda/cuda_driver.cc:936] failed to allocate 180.50M (189267968 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
2019-07-21 18:58:28.677950: I tensorflow/core/common_runtime/gpu/gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 117 MB memory) -> physical GPU (device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:03:00.0, compute capability: 6.1)
2019-07-21 18:58:28.681510: I tensorflow/core/common_runtime/gpu/gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:2 with 117 MB memory) -> physical GPU (device: 2, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0, compute capability: 6.1)
2019-07-21 18:58:28.685174: I tensorflow/core/common_runtime/gpu/gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:3 with 117 MB memory) -> physical GPU (device: 3, name: GeForce GTX 1080 Ti, pci bus id: 0000:83:00.0, compute capability: 6.1)
Found 4 subject attentions
Found 4 object attentions
Found 3 shift attentions
Found 3 inv shift attentions
17
2019-07-21 18:59:22.033085: W tensorflow/core/common_runtime/bfc_allocator.cc:219] Allocator (GPU_0_bfc) ran out of memory trying to allocate 134.20MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
2019-07-21 18:59:22.033246: W tensorflow/core/common_runtime/bfc_allocator.cc:219] Allocator (GPU_0_bfc) ran out of memory trying to allocate 55.69MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
2019-07-21 18:59:22.036407: W tensorflow/core/common_runtime/bfc_allocator.cc:219] Allocator (GPU_0_bfc) ran out of memory trying to allocate 137.62MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
2019-07-21 18:59:22.040735: W tensorflow/core/common_runtime/bfc_allocator.cc:219] Allocator (GPU_0_bfc) ran out of memory trying to allocate 146.81MiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
Traceback (most recent call last):
File "visualization.py", line 218, in
np.maximum(final_object_heatmap[0],0), 14, threshold=0.8)
File "/home/yyf/ReferringRelationships/utils/visualization_utils.py", line 100, in add_bboxes
threshold=threshold)
File "/home/yyf/ReferringRelationships/utils/visualization_utils.py", line 51, in get_bbox_from_heatmap
ymin = np.min(rows)
File "/home/yyf/ReferringRelationships/env/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 2372, in amin
out=out, **kwargs)
File "/home/yyf/ReferringRelationships/env/lib/python3.6/site-packages/numpy/core/_methods.py", line 29, in _amin
return umr_minimum(a, axis, None, out, keepdims)
ValueError: zero-size array to reduction operation minimum which has no identity
`

Could you please give me some suggestions on these problems?~

Thanks in advance~!

Bug in model definition when training Visual Genome

Traceback (most recent call last):
File "train.py", line 70, in
model = relationships_model.build_model()
File "/home/jiechen/code/ReferringRelationships/models.py", line 75, in build_model
return self.build_ssas()
File "/home/jiechen/code/ReferringRelationships/models.py", line 154, in build_ssas
subject_att = Concatenate(axis=3)(subject_outputs)
File "/home/jiechen/anaconda3/envs/rel/lib/python3.6/site-packages/keras/engine/topology.py", line 583, in call
previous_mask = _collect_previous_mask(inputs)
File "/home/jiechen/anaconda3/envs/rel/lib/python3.6/site-packages/keras/engine/topology.py", line 2752, in _collect_previous_mask
mask = node.output_masks[tensor_index]
IndexError: list index out of range

Dimension of image features

According to the paper, the dimension of image features is 14 × 14 × 512.
But, the dimension of the features used in train_visualgenome.sh is 14 × 14 × 1024.

image
The layer of ResNet50 used in train_visualgenome.sh is activation_40

Something wrong in training VRD

Set the configure '--save-best-only' and find that the val_loss just didn't improve from the first epoch.

Through the tensorboard on log, the performance on training set was normal, in which the loss trend to descend. However, the performance on val set was unexpected, in which the val_loss didn't descend including all metric on val not convergence.

unable to load a model (h5) after training

I trained on visual genome dataset, and the followings are the saved keras model.

dsdev@dsdev:/mnt/data/savedir$ ls
args.json                             model04-1.67.h5  model09-1.82.h5  model14-2.24.h5  model19-2.69.h5
events.out.tfevents.1573210626.dsdev  model05-1.66.h5  model10-1.90.h5  model15-2.40.h5  model20-2.73.h5
model01-1.66.h5                       model06-1.67.h5  model11-1.94.h5  model16-2.47.h5  model21-2.78.h5
model02-1.62.h5                       model07-1.63.h5  model12-2.04.h5  model17-2.57.h5  model22-2.81.h5
model03-1.62.h5                       model08-1.74.h5  model13-2.18.h5  model18-2.62.h5  train.log

I am trying to use the trained model (h5) to convert into protobuffer(pb) format.
Since you mentioned, in your keras checkpointer to save_weight_only as True, so I am loading model graph from model.py, and trying to load the model, i am getting this error.

model.load_weights('/home/dsdev/model16-2.47.h5')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/anaconda/envs/py35/lib/python3.5/site-packages/keras/engine/network.py", line 1166, in load_weights
    f, self.layers, reshape=reshape)
  File "/data/anaconda/envs/py35/lib/python3.5/site-packages/keras/engine/saving.py", line 1030, in load_weights_from_hdf5_group
    str(len(filtered_layers)) + ' layers.')
ValueError: You are trying to load a weight file containing 844 layers into a model with 564 layers.

The way I am loading a graph is as follow:

args = {"input_dim": 224, "feat_map_dim": 14, "hidden_dim": 1024, "num_objects": 100, "num_predicates": 70, "dropout": 0.0, "use_subject": True, "use_predicate": True, "use_object": True,  "nb_conv_att_map": 6, "nb_conv_im_map": 0, "cnn": "resnet", "feat_map_layer": "activation_40", "conv_im_kernel": 0, "conv_predicate_kernel": 7,  "conv_predicate_channels": 10, "model": "ssas", "use_internal_loss": True, "internal_loss_weight": 1.0, "iterations": 3,  "attention_conv_kernel": 3, "refinement_conv_kernel": 3, "output_dim": 14, "embedding_dim": 512, "finetune_cnn": True}
args = parse_args()

metrics = get_metrics(args.output_dim, args.heatmap_threshold)
relationships_model = ReferringRelationshipsModel(args)
model = relationships_model.build_model()
optimizer = get_opt(opt=args.opt, lr=args.lr)

if args.loss_func == 'weighted':
  loss_func = get_loss_func(args.w1)
else:
  loss_func = 'binary_crossentropy'

losses = [loss_func, loss_func]
model.compile(loss=losses, optimizer=optimizer, metrics=metrics)
model.load_weights('/home/dsdev/model16-2.47.h5')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.