예제 #1
0
def main():
    """
        Use main if you want to run the complete program with init, train and prediction of and example image.
        To be able to run main, make sure:
        -no more than two projects created in Azure Custom Vision
        -no more than 10 iterations done in one projectS
    """
    test_url = "https://newdataset.blob.core.windows.net/oldimgcontainer/old/airplane/4554736336371712.png"

    classifier = Classifier()

    # classify image with URL reference
    result, best_guess = classifier.predict_image_url(test_url)
    print(f"url result:\n{best_guess} url result {result}")

    # classify image
    with open("../data/cv_testfile.png", "rb") as f:
        result, best_guess = classifier.predict_image(f)
        print(f"png result:\n{result}")

    with api.app.app_context():
        labels = models.get_all_labels()

    classifier.upload_images(labels, "old")
    classifier.train(labels)
예제 #2
0
    def retrain(self):
        """
            Train model on all labels and update iteration.
        """
        with api.app.app_context():
            labels = models.get_all_labels()

        self.upload_images(labels, setup.CONTAINER_NAME_NEW)
        try:
            self.train(labels)
        except CustomVisionErrorException as e:
            msg = "No changes since last training"
            print(e, "exiting...")
            raise excp.BadRequest(msg)
예제 #3
0
    def hard_reset_retrain(self):
        """
            Train model on all labels and update iteration.
            This method sleeps for 60 seconds to make sure all
            old images are deleted from custom vision before
            uploading original dataset.
        """
        with api.app.app_context():
            labels = models.get_all_labels()

        # Wait 60 seconds to make sure all images are deleted in custom vision
        time.sleep(60)
        self.upload_images(labels, setup.CONTAINER_NAME_ORIGINAL)
        try:
            self.train(labels)
        except CustomVisionErrorException as e:
            msg = "No changes since last training"
            print(e, "exiting...")
            raise excp.BadRequest(msg)