2

My friend has sent me the .bytes file from unity for machine learning model. But I don't know how to open it in python for ML. Could any one able to give me the answer about the .bytes file in unity.

  1. What is the purpose of it?
  2. How to use it for python?
Mike Wise
  • 22,131
  • 8
  • 81
  • 104
EKNATH KULKARNI
  • 394
  • 1
  • 5
  • 13

2 Answers2

4

What is the purpose of it?

It's a raw bytes of a file. Let's say that you want to import a file into Unity Resources folder and the file is not one of the supported resources files in Unity such as .png, .mp3 and .mp4, but you want Unity to include this special file extension in the final build, you change the file extension to .bytes. It will be included in the final build and you can load and retrieve it during run-time with the Resources API and TextAsset.bytes. It's simply used to hold binary data.

How to use it for python?

You can like you would with any binary file in python.

byte = f.read(1)
binary_string = bin(int(binascii.hexlify(byte), 16))[2:].zfill(8)

See this for more information.

Programmer
  • 121,791
  • 22
  • 236
  • 328
1

.bytes file has many usages like in unity 1: Used as the text asset 2: Used as graph model for the brain in ML

Now point is how to use it in python 1: bytes file is directly convert to the .pb file in python by just renaming. for more details refer: https://github.com/Unity-Technologies/ml-agents/issues/735

Now how to use it in python code: https://gist.github.com/jubjamie/2eec49ca1e4f58c5310d72918d991ef6

EKNATH KULKARNI
  • 394
  • 1
  • 5
  • 13
  • I clearly explained what .bytes is used for. FYI, it has nothing to do with "graph model for the brain in ML" as you mentioned in your answer. It's used to represent binary files not supported in Unity. – Programmer Jul 24 '18 at 07:55
  • After generating ML model, we are storing it in .bytes file which we are using to for brain. I tried your code by taking the bytes file as input but unable to read it, I am getting the binary raw data not actual data – EKNATH KULKARNI Jul 24 '18 at 09:02
  • You can then load the binary raw data with whatever API or library you want to use your binary file with and in this case is the tensorflow API. I was just pointing out that " .bytes" has nothing to do with "graph model". If you still think it does then you are free to accept your own answer. By looking at the title of your question, I doubt your answer would be useful to those who will search for this in the future. – Programmer Jul 24 '18 at 09:26
  • I am bit confused, by client has given me .bytes file and told me to train the model by using python so that's why I put the question. I tried visualize the model but unable to do so – EKNATH KULKARNI Jul 24 '18 at 09:39
  • I've also seen .bytes file used for a sqlite database. Not sure if there's a way to add .db3 to a supported Unity file, but .bytes certainly works. – Tac Tacelosky Nov 06 '20 at 16:11