Skip to content

add Tensorflow Hub detector support - #501

Closed
kadirnar wants to merge 36 commits into
obss:mainfrom
kadirnar:tfhub
Closed

kadirnar wants to merge 36 commits into
obss:mainfrom
kadirnar:tfhub

Conversation

@kadirnar

@kadirnar kadirnar commented Jun 18, 2022 •

Copy link
Copy Markdown
Contributor

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

fcakyon commented Jun 19, 2022 •

Copy link
Copy Markdown
Collaborator

@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

Comment thread sahi/model.py Outdated
Comment thread sahi/model.py Outdated

@fcakyon fcakyon left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

vazgectim bu degisiklikten.

Comment thread sahi/utils/tfhub.py Outdated
Comment thread sahi/model.py Outdated
Comment thread sahi/model.py Outdated
Comment thread sahi/model.py Outdated
Comment thread sahi/model.py Outdated
Comment thread sahi/model.py Outdated
Comment thread tests/test_tfhub.py Outdated
Comment thread tests/test_tfhub.py Outdated
Comment thread tests/test_tfhub.py Outdated
@kadirnar

kadirnar commented Jun 19, 2022 •

Copy link
Copy Markdown
Contributor Author

@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

fcakyon commented Jun 19, 2022

Copy link
Copy Markdown
Collaborator

@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.

Comment thread .github/workflows/ci.yml Outdated
Comment thread sahi/utils/tfhub.py Outdated
Comment thread sahi/utils/tfhub.py Outdated
Comment thread sahi/utils/tfhub.py Outdated
Comment thread sahi/model.py Outdated
Comment thread sahi/model.py Outdated
Comment thread tests/test_tensorflow.py Outdated
Comment thread .github/workflows/ci.yml
Comment thread sahi/model.py
Comment thread sahi/model.py
@fcakyon

fcakyon commented Aug 29, 2022 •

Copy link
Copy Markdown
Collaborator

@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

kadirnar commented Aug 30, 2022 •

Copy link
Copy Markdown
Contributor Author

@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

fcakyon commented Aug 30, 2022

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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

fcakyon commented Aug 30, 2022

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Contributor Author

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

Comment thread sahi/model.py Outdated
Comment thread sahi/model.py Outdated
Comment thread sahi/model.py Outdated
Co-authored-by: fatih <34196005+fcakyon@users.noreply.github.com>
Comment thread sahi/model.py Outdated
Comment thread sahi/model.py Outdated
Co-authored-by: fatih <34196005+fcakyon@users.noreply.github.com>

@fcakyon fcakyon left a comment

Copy link
Copy Markdown
Collaborator

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

Comment thread sahi/model.py Outdated
@kadirnar

Copy link
Copy Markdown
Contributor Author

@fcakyon fcakyon closed this Nov 22, 2024
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

Development

Successfully merging this pull request may close these issues.

2 participants