kbelenky / open_sorts

Sorting machine for TCGs such as Magic: The Gathering
GNU General Public License v3.0
18 stars 2 forks source link

Generating embedding vectors for new sets #4

Open kcjones opened 1 year ago

kcjones commented 1 year ago

I am wondering if you can provide guidance on how to update the embedding dictionary with newer sets?

Is it a matter of 1) Sourcing images (and data) of cards. (seems allowable in the Scryfall api); 2) Generating embedding vectors from images, similar to what you do in part of card_recognizer.recognize_by_embedding; 3) Adding the new embedding data to embedding_dictionary.pickle and updating card_catalog.json. ?

Am I missing a major step or misunderstanding the process? For Scryfall, what image format/size do you choose for generation? https://scryfall.com/docs/api/images

I attempted generating vectors using this method but am not matching up with your results. I suspect either the source image is different (using skryfall large), I'm not appropriately preprocessing the image, or I'm misunderstanding the process. Would you be willing to share non-Scryfall portions of your update script?

Thank you for making this project available.

kbelenky commented 1 year ago

That's pretty much exactly the process. I have some scripts to do it, but they're not something I'd be willing to share or support. With all the myriad promos and stuff, there's a lot of cards that I don't want polluting my database, so I filter them out, but it's all very arbitrary and ad hoc. Also, Scryfall's database is not terribly consistent in what it considers a face or how it's represented. Sometimes fused cards (like Turn // Burn) are represented as having two face images, sometimes they're represented with one face image. And then, don't even get me started on meld cards.

The one thing to note, is that I append an extra "_0" or "_1" to the end of the scryfall id to indicate if it's the front face or the back face, since scryfall uses the id to refer to "the piece of cardboard", not individual faces.

You should be able to use pretty much any of the thumbnails, so long as you rescale them properly. The recognizer uses pretty severely downscaled cards, so it's not sensitive to image quality.

Most likely, the reason why you're not getting good embeddings is because of preprocessing. The embedding network is built off of MobileNetV2, which requires the input images to be scaled with pixel values [-1 .. 1]: https://www.tensorflow.org/api_docs/python/tf/keras/applications/mobilenet_v2/preprocess_input