Ejemplo n.º 1
0
    def put(self, request, book):
        book = DatabaseBook(book)

        if not book.exists():
            return Response(status=status.HTTP_400_BAD_REQUEST)

        file = book.local_path("virtual_keyboard.json")
        json.dump(json.loads(request.body, encoding="utf-8"),
                  open(file, 'w'),
                  indent=4)
        return Response()
Ejemplo n.º 2
0
    def get(self, request, book):
        book = DatabaseBook(book)

        if not book.exists():
            return Response(status=status.HTTP_400_BAD_REQUEST)

        file = book.local_path("virtual_keyboard.json")
        if not os.path.exists(file):
            file = book.local_default_virtual_keyboards_path('default.json')

        with open(file) as f:
            return Response(json.load(f))
    def load(book: DatabaseBook):
        path = book.local_path('book_dictionary.json')
        try:
            with open(path) as f:
                d = DatabaseDictionary.from_book_json(book, json.load(f))
        except FileNotFoundError:
            try:
                path = os.path.join(settings.BASE_DIR,
                                    'internal_storage',
                                    'default_dictionary',
                                    'default_dictionary.json')
                with open(path) as f:

                    d = DatabaseDictionary.from_book_json(book, json.load(f))
            except FileNotFoundError:
                d = DatabaseDictionary(b_id=book.book)

        return d
 def to_file(self, book: DatabaseBook):
     self.b_id = book.book
     s = self.to_json()
     with open(book.local_path('book_dictionary.json'), 'w') as f:
         js = json.dumps(s, indent=2)
         f.write(js)
Ejemplo n.º 5
0
    Clefs = 5
    Accidentals = 6

    Size = 7


global_counts = np.zeros(Counts.Size, dtype=np.uint32)

table = PrettyTable(["Dataset"] +
                    [str(Counts(i))[7:] for i in range(Counts.Size)])
for book_name in args.datasets:
    book = DatabaseBook(book_name)
    counts = np.zeros(Counts.Size, dtype=np.uint32)
    if not book.exists():
        raise ValueError("Dataset '{}' does not exist at '{}'".format(
            book.book, book.local_path()))

    for page in book.pages():
        pcgts = PcGts.from_file(page.file('pcgts'))
        counts[Counts.Pages] += 1

        for mr in pcgts.page.music_regions:
            for ml in mr.staffs:
                counts[Counts.Staves] += 1
                counts[Counts.StaffLines] += len(ml.staff_lines)

                for s in ml.symbols:
                    if isinstance(s, Neume):
                        n: Neume = s
                        counts[Counts.Symbols] += len(n.notes)
                        counts[Counts.NoteComponents] += len(n.notes)
Ejemplo n.º 6
0
        cm.plot_confusion_matrix(normalize=True)
        return f_metrics.mean(axis=0), counts.sum(
            axis=0), acc_counts, acc_acc, total_diffs


if __name__ == '__main__':
    from omr.symboldetection.predictor import SymbolDetectionPredictor, create_predictor, PredictorTypes, SymbolDetectionPredictorParameters
    from prettytable import PrettyTable
    from database import DatabaseBook
    b = DatabaseBook('Graduel')
    eval_pcgts = [PcGts.from_file(p.file('pcgts')) for p in b.pages()[12:13]]
    print([e.page.location.local_path() for e in eval_pcgts])
    predictor = create_predictor(
        PredictorTypes.PIXEL_CLASSIFIER,
        SymbolDetectionPredictorParameters(
            [b.local_path(os.path.join('pc_symbol_detection', 'model'))]))
    gt_symbols, pred_symbols = [], []
    for p in predictor.predict(eval_pcgts):
        pred_symbols.append(p.symbols)
        gt_symbols.append(p.line.operation.music_line.symbols)

    evaluator = SymbolDetectionEvaluator()
    metrics, counts, acc_counts, acc_acc, diffs = evaluator.evaluate(
        gt_symbols, pred_symbols)

    at = PrettyTable()

    at.add_column("Type", ["All", "All", "Notes", "Clefs", "Accids"])
    at.add_column("TP", counts[:, Counts.TP])
    at.add_column("FP", counts[:, Counts.FP])
    at.add_column("FN", counts[:, Counts.FN])