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

add Tensorflow Hub detector support #501

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open

Conversation

kadirnar
Copy link
Contributor

@kadirnar kadirnar commented Jun 18, 2022

Testlerden geçebilmesi için tensorflow ve tensorflow_hub kütüphanelerin kurulması gerekiyor.

  • package_testing.yml
  • ci.yml
- name: Install tensorflow and tensorflow_hub
  run: >
    pip install  tensorflow
    pip install tensorflow_hub

Bu format uygun mudur? @fcakyon

@fcakyon
Copy link
Collaborator

fcakyon commented Jun 19, 2022

@kadirnar Su sekilde versiyon belirtebiliriz:

- name: Install tensorflow(2.9.1) and tensorflow_hub(0.12.0)
  run: >
    pip install  tensorflow==2.9.1
    pip install tensorflow_hub==0.12.0

sahi/model.py Outdated Show resolved Hide resolved
sahi/model.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@fcakyon fcakyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vazgectim bu degisiklikten.

sahi/utils/tfhub.py Outdated Show resolved Hide resolved
sahi/model.py Outdated Show resolved Hide resolved
sahi/model.py Outdated Show resolved Hide resolved
sahi/model.py Outdated Show resolved Hide resolved
sahi/model.py Outdated Show resolved Hide resolved
sahi/model.py Outdated Show resolved Hide resolved
tests/test_tfhub.py Outdated Show resolved Hide resolved
tests/test_tfhub.py Outdated Show resolved Hide resolved
tests/test_tfhub.py Outdated Show resolved Hide resolved
@kadirnar
Copy link
Contributor Author

kadirnar commented Jun 19, 2022

@fcakyon test kodları paket kurulumlarından geçemiyor. Bunun için nasıl düzeltme yapmalıyım? (Bu düzeltmeden sonra reformat yapacağım)

@fcakyon
Copy link
Collaborator

fcakyon commented Jun 19, 2022

@fcakyon test kodları paket kurulumlarından geçemiyor. Bunun için nasıl düzeltme yapmalıyım? (Bu düzeltmeden sonra reformat yapacağım)

Testlerin calismasi icin black ve isort ile reformat yapip pushlaman gerekiyor. Linting'de takilmis tum testler.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
sahi/utils/tfhub.py Outdated Show resolved Hide resolved
sahi/utils/tfhub.py Outdated Show resolved Hide resolved
sahi/utils/tfhub.py Outdated Show resolved Hide resolved
sahi/model.py Outdated Show resolved Hide resolved
sahi/model.py Outdated Show resolved Hide resolved
tests/test_tensorflow.py Outdated Show resolved Hide resolved
sahi/model.py Outdated Show resolved Hide resolved
sahi/model.py Show resolved Hide resolved
sahi/model.py Show resolved Hide resolved
@fcakyon
Copy link
Collaborator

fcakyon commented Aug 29, 2022

@kadirnar su doctaki bilgiyi kullanarak tensorflow icin otomatik device secme eklememiz gerekiyor bu PRi mergeleyebilmemiz icin: https://www.tensorflow.org/guide/gpu#overview

ONEMLI NOT: maindeki son degisiklikleri mergeldim, localinde calismaya baslamadan once pullasan cok iyi olur 👍

@kadirnar
Copy link
Contributor Author

kadirnar commented Aug 30, 2022

@kadirnar su doctaki bilgiyi kullanarak tensorflow icin otomatik device secme eklememiz gerekiyor bu PRi mergeleyebilmemiz icin: https://www.tensorflow.org/guide/gpu#overview

ONEMLI NOT: maindeki son degisiklikleri mergeldim, localinde calismaya baslamadan once pullasan cok iyi olur 👍

Auto device kodlarını nasıl entegre etmemi tavsiye edersiniz? Tensorflowhub classı ıcındekı load model fonksiyonuna mı?

Yoksa from sahi.utils.tensorflow import is_tensorflow_cuda_available fonksiyonu mu yazmalıyım?

Örnek Kod:

if tf.test.is_gpu_available():
    self.device = "/gpu:0"
else:
    self.device = "/cpu:0"

Ayrıca test kodlarını çalıştırırken torch kütüphanesini de yüklemek zorunda oluyorum. (SAHI torch kütüphanesi ile yazıldığı için normal olduğunu düşündüm)

https://github.com/obss/sahi/blob/main/sahi/model.py#L668

@fcakyon
Copy link
Collaborator

fcakyon commented Aug 30, 2022

Evet şu anda torch SAHI’de zorunlu dependency.

device olayı için şöyle bir şey yapabiliriz:
DetectionModel için set_device diye bir fonksiyon tanımlayıp şu anki device set etme satırını ona taşırız.

tensofflubhubdetectionmodel içinde set_device fonksiyonunu yeniden tanımlayabilirsin yazdığın şekilde

@kadirnar
Copy link
Contributor Author

Evet şu anda torch SAHI’de zorunlu dependency.

device olayı için şöyle bir şey yapabiliriz: DetectionModel için set_device diye bir fonksiyon tanımlayıp şu anki device set etme satırını ona taşırız.

tensofflubhubdetectionmodel içinde set_device fonksiyonunu yeniden tanımlayabilirsin yazdığın şekilde

def set_device(self):
    import tensorflow as tf
    if self.device is None:
        try:
            if tf.test.is_gpu_available():
                self.device = "/gpu:0"
            else:
                self.device = "/cpu:0"
                
        except Exception as e:
            raise Exception("Error setting device: ", e)

Hata mesajı ve kodlar için öneriniz var mı? Yoksa bu şekilde göndereceğim.

@fcakyon
Copy link
Collaborator

fcakyon commented Aug 30, 2022

Güzel olmuş eline sağlık, try except’e gerek olmayabilir. torch’ta yaptığımız gibi try except yapmadan set edebiliriz gpu/cpu

@kadirnar
Copy link
Contributor Author

Readme.md dosyasındaki reformatter kodu hata veriyor. Eski reformatter kodunu çalıştırdım.

sahi/model.py Outdated Show resolved Hide resolved
sahi/model.py Outdated Show resolved Hide resolved
sahi/model.py Outdated Show resolved Hide resolved
Co-authored-by: fatih <34196005+fcakyon@users.noreply.github.com>
sahi/model.py Outdated Show resolved Hide resolved
sahi/model.py Outdated Show resolved Hide resolved
Co-authored-by: fatih <34196005+fcakyon@users.noreply.github.com>
Copy link
Collaborator

@fcakyon fcakyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

67-69 satirlari arasinin silinmesi, onun yerine set_device fonksiyonu cagirilarak device ayarlanmasi gerekiyor

sahi/model.py Outdated Show resolved Hide resolved
@kadirnar
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request workflows ci/cd workflows
Projects
None yet
2 participants