Skip to content

Commit

Permalink
add from_aistudio up and load unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
LokeZhou committed Nov 28, 2023
1 parent 4c94373 commit e6ae2f6
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/processors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
91 changes: 91 additions & 0 deletions tests/processors/test_from_aistudio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys
import unittest

sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "../.."))

from paddlemix.models.groundingdino.modeling import GroundingDinoModel
from paddlemix.processors.groundingdino_processing import (
GroudingDinoImageProcessor,
GroudingDinoTextProcessor,
)
from tests.testing_utils import ai_studio_token, slow

repo_id = "aistudio/groundingdino-swint-ogc"
bos_model_name = "GroundingDino/groundingdino-swint-ogc"


class FromAiStudioTester:
def __init__(self):
self.bos_model_name = bos_model_name
self.token = ai_studio_token
self.repo_id = repo_id

def prepare_from_bos(self):
model = GroundingDinoModel.from_pretrained(self.bos_model_name)
image_processor = GroudingDinoImageProcessor.from_pretrained(self.bos_model_name)
text_processor = GroudingDinoTextProcessor.from_pretrained(self.bos_model_name)

return model, image_processor, text_processor


class AIStudioUpTester(unittest.TestCase):
def setUp(self):
self.tester = FromAiStudioTester()
self.model, self.image_processor, self.text_processor = self.tester.prepare_from_bos()

@slow
def test_model_up_aistusio(self):
self.model.save_to_aistudio(
repo_id=self.tester.repo_id,
token=self.tester.token,
private=True,
license="Apache License 2.0",
exist_ok=True,
safe_serialization=True,
)

def test_processor_up_aistusio(self):
self.image_processor.save_to_aistudio(
repo_id=self.tester.repo_id,
token=self.tester.token,
private=True,
license="Apache License 2.0",
exist_ok=True,
)
self.text_processor.save_to_aistudio(
repo_id=self.tester.repo_id,
token=self.tester.token,
private=True,
license="Apache License 2.0",
exist_ok=True,
)


class AIStudioLoadTester(unittest.TestCase):
def setUp(self):
self.tester = FromAiStudioTester()

@slow
def test_model_load_aistusio(self):
GroundingDinoModel.from_pretrained(self.tester.repo_id, from_aistudio=True)

def test_processor_load_aistusio(self):
GroudingDinoTextProcessor.from_pretrained(self.tester.repo_id, from_aistudio=True)

def image_processor_load_aistusio(self):
GroudingDinoImageProcessor.from_pretrained(self.tester.repo_id, from_aistudio=True)
1 change: 1 addition & 0 deletions tests/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def get_bool_from_env(key, default_value=False):


_run_slow_test = get_bool_from_env("RUN_SLOW_TEST")
ai_studio_token = os.getenv("AI_STUDIO_TOKEN")


def slow(test):
Expand Down

0 comments on commit e6ae2f6

Please sign in to comment.