Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where is the tensorflow version? #195

Closed
bw4sz opened this issue Jun 4, 2021 · 13 comments
Closed

Where is the tensorflow version? #195

bw4sz opened this issue Jun 4, 2021 · 13 comments
Labels

Comments

@bw4sz
Copy link
Collaborator

bw4sz commented Jun 4, 2021

This issue outlines the transition of this repo from a tensorflow backend to pytorch. The tensorflow has breaking changes upstream from a keras-resnet dependency. See

#192

We have merged the repo https://github.com/weecology/DeepForest-pytorch into this repo and this will be the main branch starting a version 1.0

The tensorflow version is still available https://github.com/weecology/DeepForest/tree/tensorflow, but will no longer be mantained.

@bw4sz bw4sz mentioned this issue Jun 4, 2021
4 tasks
@ML-learner79
Copy link

I am learning the deep forest and using the old tf- keras based codebase. Today I was tying the train a model. In the keras baed old training code. I am getting errors from here.
test_model = deepforest.deepforest()
test_model.use_release()
It looks like This is pointing to the latest PyTorch-based release. Is there a way to get the last old Keras-based release?

Reading config file: D:\Work\miniconda\tf_gpu\lib\site-packages\deepforest\data\deepforest_config.yml
A blank deepforest object created. To perform prediction, either train or load an existing model.
Model from DeepForest release https://github.com/weecology/DeepForest/releases/tag/1.0.0 was already downloaded. Loading model from file.
Loading pre-built model: https://github.com/weecology/DeepForest/releases/tag/1.0.0
Traceback (most recent call last):
File "training.py", line 94, in
test_model.use_release()
File "D:\Work\miniconda\tf_gpu\lib\site-packages\deepforest\deepforest.py", line 173, in use_release
self.model = utilities.read_model(self.weights, self.config)
File "D:\Work\miniconda\tf_gpu\lib\site-packages\deepforest\utilities.py", line 51, in read_model
model = models.load_model(model_path, backbone_name='resnet50')
File "D:\Work\miniconda\tf_gpu\lib\site-packages\keras_retinanet\models_init_.py", line 83, in load_model
return keras.models.load_model(filepath, custom_objects=backbone(backbone_name).custom_objects)
File "D:\Work\miniconda\tf_gpu\lib\site-packages\keras\engine\saving.py", line 492, in load_wrapper
return load_function(*args, **kwargs)
File "D:\Work\miniconda\tf_gpu\lib\site-packages\keras\engine\saving.py", line 583, in load_model
with H5Dict(filepath, mode='r') as h5dict:
File "D:\Work\miniconda\tf_gpu\lib\site-packages\keras\utils\io_utils.py", line 191, in init
self.data = h5py.File(path, mode=mode)
File "D:\Work\miniconda\tf_gpu\lib\site-packages\h5py_hl\files.py", line 408, in init
swmr=swmr)
File "D:\Work\miniconda\tf_gpu\lib\site-packages\h5py_hl\files.py", line 173, in make_fid
fid = h5f.open(name, flags, fapl=fapl)
File "h5py_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py\h5f.pyx", line 88, in h5py.h5f.open
OSError: Unable to open file (file signature not found)

@bw4sz
Copy link
Collaborator Author

bw4sz commented Jun 8, 2021 via email

@ML-learner79
Copy link

Thanks for the update. Now I am seeing something strange in training. Previously when I use test_model.use_release(). and train using my dataset Mean Average Precision was around 0.85 but Now when I download and use the model. test_model = deepforest.deepforest(saved_model="C:/Download/NEON.h5") For the same data mAP is significantly reduced to around 0.40. I am not sure what might have made such changes.

@bw4sz
Copy link
Collaborator Author

bw4sz commented Jun 8, 2021 via email

@ML-learner79
Copy link

Hey, thanks for the prompt response. Here is code
import os
from deepforest import get_data
from deepforest import deepforest
from deepforest import utilities
from deepforest import preprocess

path_train = get_data("D:/Work/training/orthomosaic_image.jpg")
crop_dir = os.getcwd()
train_annotations= preprocess.split_raster(path_to_raster=path_train, annotations_file="training_anotation.csv", base_dir=crop_dir, patch_size=1600, patch_overlap=0.10)

annotations_file = os.path.join(crop_dir, "training_example.csv")
train_annotations.to_csv(annotations_file,index=False, header=None)

import time
st = time.time()
#Load the latest release
#test_model = deepforest.deepforest()
#test_model.use_release()
test_model = deepforest.deepforest(saved_model="C:/Download/NEON.h5")

test_model.config["epochs"] = 20
test_model.config["save-snapshot"] = False
test_model.config["random_transform"] = True
test_model.train(annotations=annotations_file, input_type="fit_generator")
test_model.model.save("./model/16002_RGB.h5")
test_model.model.save_weights("./model/16002_RGB_weight.h5")

print('Model Saving Completed')
print(time.time()-st)

print('Model Evaluation')

annotations_file = get_data(annotations_file)
mAP = test_model.evaluate_generator(annotations=annotations_file)
print("Mean Average Precision is: {:.3f}".format(mAP))

test_model.plot_curves()

The one thing I am confused about is how to set up the deepforest.yml file. as I am not using the use_release Is that causing the problem?

@bw4sz
Copy link
Collaborator Author

bw4sz commented Jun 8, 2021

Nothing obvious jumps out. In truth I would recommend upgrading to 1.0.0, the pytorch branch performs well. But let's keep trying here. One thing I see is on use_release(), the weights are added to config,

self.config["weights"] = self.weights

self.config["weights"] = self.weights

go ahead and add that before training in case it was assumed to be inherent from use_release()

test_model.config["weights] = "C:/Download/NEON.h5"

@ML-learner79
Copy link

Thanks for the update. I will update this and test it. later in the week I will update PyTorch that was the last option I was thinking of. Will update you on the progress in a couple of days.

@bw4sz
Copy link
Collaborator Author

bw4sz commented Jun 9, 2021

Just brainstorming here if you do see any difference between loading the model (including the optimizer) or just the weights

reloaded = deepforest.deepforest(weights="example_save_weights.h5")

If you can try both, that would help. I cannot reproduce any difference in performance between the use_release() and just downloading the release model and pointing at it.

@ML-learner79
Copy link

Yes the earlier issue was me just loading the model but not the weight
test_model = deepforest.deepforest(saved_model="C:/Download/NEON.h5")
test_model.config["weights] = "C:/Download/NEON.h5"
Adding these two solve the problem and now the training mAP is align with previous.

@bw4sz
Copy link
Collaborator Author

bw4sz commented Jun 9, 2021

fascinating. I'll add to docs.

@bw4sz
Copy link
Collaborator Author

bw4sz commented Jun 9, 2021

@github-actions
Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Aug 16, 2021
@github-actions
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants