浏览代码

Installation through Python for Unity instead of direct pip install

/pyrception-integration
leopoldo-zugasti 4 年前
当前提交
a4e2c24c
共有 4 个文件被更改,包括 52 次插入23 次删除
  1. 52
      com.unity.perception/Editor/Pyrception/PyrceptionInstaller.cs
  2. 10
      com.unity.perception/Editor/Pyrception/pyrception-utils/pyrception_utils/preview.py
  3. 6
      com.unity.perception/Editor/Pyrception/pyrception-utils/Dockerfile
  4. 7
      com.unity.perception/Editor/Pyrception/pyrception-utils/Dockerfile.meta

52
com.unity.perception/Editor/Pyrception/PyrceptionInstaller.cs


}*/
string path = Application.dataPath.Replace("/Assets", "");
string packagesPath = Application.dataPath.Replace("/Assets","/Library/PythonInstall/Scripts");
packagesPath = packagesPath.Replace("/", "\\");
pathToData = pathToData.Replace("/", "\\");
#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
path = path.Replace(" ", "\\ ");

#if UNITY_EDITOR_WIN
command = $"cd \"{path}\\DataInsightsEnv\\Scripts\\\" && activate && cd \"{pathToData}\\..\" && \"{path}\\DataInsightsEnv\\Scripts\\pyrception-utils.exe\" preview --data=\".\"";
//command = $"cd \"{path}\\DataInsightsEnv\\Scripts\\\" && activate && cd \"{pathToData}\\..\" && \"{path}\\DataInsightsEnv\\Scripts\\pyrception-utils.exe\" preview --data=\".\"";
command = $"cd \"{pathToData}\\..\" && \"{packagesPath}\\pyrception-utils.exe\" preview --data=\".\"";
command = $"cd \"{path}/DataInsightsEnv/bin\";source activate;cd \"{pathToData}/..\";\"{path}/DataInsightsEnv/bin/pyrception-utils\" preview --data=\".\"";
//command = $"cd \"{path}/DataInsightsEnv/bin\";source activate;cd \"{pathToData}/..\";\"{path}/DataInsightsEnv/bin/pyrception-utils\" preview --data=\".\"";
command = $"cd \"{pathToData}\\..\" && \"{packagesPath}\\pyrception-utils\" preview --data=\".\"";
#endif
int ExitCode = 0;
ExecuteCMD(command, ref ExitCode, waitForExit: false, displayWindow: true);

//==============================CHECK PIP3 IS INSTALLED======================================
int ExitCode = 0;
ExecuteCMD("pip3", ref ExitCode);
/*ExecuteCMD("pip3", ref ExitCode);
UnityEngine.Debug.LogError("Python >= 3 and pip3 must be installed.");
UnityEngine.Debug.LogError("Python >= 3 and pip3 must be installed and available on PATH.");
}
}*/
#if UNITY_EDITOR_WIN
string packagesPath = Application.dataPath.Replace("/Assets","/Library/PythonInstall/Scripts");
#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
string packagesPath = Application.dataPath.Replace("/Assets","/Library/PythonInstall/bin");
#endif
packagesPath = packagesPath.Replace("/", "\\");
packagesPath = packagesPath.Replace(" ", "\\ ");
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Installing virtualenv...", 0 / steps);
//EditorUtility.DisplayProgressBar("Setting up Pyrception", "Installing virtualenv...", 0 / steps);
ExecuteCMD($"pip3 install virtualenv", ref ExitCode);
//ExecuteCMD($"\"{packagesPath}\\pip3.bat\" install virtualenv", ref ExitCode);
ExecuteCMD($"pip3 install --target=\"{path}/virtualenvDI\" virtualenv", ref ExitCode); //(maybe add --no-user)
//ExecuteCMD($"pip3 install --target=\"{path}/virtualenvDI\" virtualenv", ref ExitCode); //(maybe add --no-user)
#endif
if (ExitCode != 0) {
EditorUtility.ClearProgressBar();

//==============================CREATE VIRTUALENV NAMED DataInsightsEnv======================================
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Setting up virtualenv instance...", 1f / steps);
//EditorUtility.DisplayProgressBar("Setting up Pyrception", "Setting up virtualenv instance...", 1f / steps);
ExecuteCMD($"virtualenv -p python3 \"{path}\\DataInsightsEnv\"", ref ExitCode);
//ExecuteCMD($"\"{packagesPath}\\virtualenv.exe\" -p python3 \"{path}\\DataInsightsEnv\"", ref ExitCode);
ExecuteCMD("export PYTHONPATH=\"${PYTHONPATH}:"+$"{path}/virtualenvDI\";"+$"\"{virtualenvPath}/virtualenv\" -p python3 \"{path}/DataInsightsEnv\"", ref ExitCode);
//ExecuteCMD("export PYTHONPATH=\"${PYTHONPATH}:"+$"{path}/virtualenvDI\";"+$"\"{virtualenvPath}/virtualenv\" -p python3 \"{path}/DataInsightsEnv\"", ref ExitCode);
#endif
if (ExitCode != 0) {
EditorUtility.ClearProgressBar();

//==============================COPY ALL PYRCEPTION FILES FOR INSTALLATION======================================
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Getting pyrception files...", 2f / steps);
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Getting pyrception files...", 1.5f / steps);
ExecuteCMD($"XCOPY /E/I/Y \"{pyrceptionPath}\" \"{path}\\DataInsightsEnv\\pyrception-util\"", ref ExitCode);
//ExecuteCMD($"XCOPY /E/I/Y \"{pyrceptionPath}\" \"{path}\\DataInsightsEnv\\pyrception-util\"", ref ExitCode);
ExecuteCMD($"XCOPY /E/I/Y \"{pyrceptionPath}\" \"{packagesPath}\\..\\pyrception-util\"", ref ExitCode);
ExecuteCMD($"\\cp -r \"{pyrceptionPath}\" \"{path}/DataInsightsEnv/pyrception-util\"", ref ExitCode);
//ExecuteCMD($"\\cp -r \"{pyrceptionPath}\" \"{path}/DataInsightsEnv/pyrception-util\"", ref ExitCode);
ExecuteCMD($"\\cp -r \"{pyrceptionPath}\" \"{packagesPath}\\..\\pyrception-util\"", ref ExitCode);
#endif
if (ExitCode != 0) {
EditorUtility.ClearProgressBar();

//==============================INSTALL PYRCEPTION IN THE VIRTUALENV======================================
#if UNITY_EDITOR_WIN
ExecuteCMD($"\"{path}\\DataInsightsEnv\\Scripts\\activate\" && cd \"{path}\\DataInsightsEnv\\pyrception-util\" && pip3 --no-cache-dir install -e . && deactivate", ref ExitCode);
//ExecuteCMD($"\"{path}\\DataInsightsEnv\\Scripts\\activate\" && cd \"{path}\\DataInsightsEnv\\pyrception-util\" && \"{packagesPath}\"\\pip3 --no-cache-dir install -e . && deactivate", ref ExitCode);
ExecuteCMD($"cd \"{packagesPath}\\..\\pyrception-util\" && \"{packagesPath}\"\\pip3.bat install --no-warn-script-location --no-cache-dir -e .", ref ExitCode);
ExecuteCMD($"source \"{path}/DataInsightsEnv/bin/activate\"; cd \"{path}/DataInsightsEnv/pyrception-util\"; pip3 --no-cache-dir install -e .; deactivate", ref ExitCode);
//ExecuteCMD($"source \"{path}/DataInsightsEnv/bin/activate\"; cd \"{path}/DataInsightsEnv/pyrception-util\"; pip3 --no-cache-dir install -e .; deactivate", ref ExitCode);
ExecuteCMD($"cd \"{packagesPath}\\..\\pyrception-util\"; \"{packagesPath}\"\\pip3 --no-warn-script-location --no-cache-dir install -e ., ref ExitCode);
#endif
if (ExitCode != 0) {
EditorUtility.ClearProgressBar();

info.CreateNoWindow = !displayWindow;
info.UseShellExecute = !waitForExit;
info.RedirectStandardOutput = redirectOutput && waitForExit;
info.RedirectStandardError = true && waitForExit;
info.RedirectStandardError = waitForExit;
Process cmd = Process.Start(info);

ExitCode = cmd.ExitCode;
if (ExitCode != 0)
{
UnityEngine.Debug.LogError($"Error - {ExitCode} - Failed to execute: {command} - {cmd.StandardError.ReadToEnd()}");
UnityEngine.Debug.LogError($"Error - {ExitCode} - Failed to execute: {command} - {/*cmd.StandardError.ReadToEnd()*/output}");
}
cmd.Close();

10
com.unity.perception/Editor/Pyrception/pyrception-utils/pyrception_utils/preview.py


foreground = PIL.Image.fromarray(rgba)
image = image.copy()
image.paste(foreground,(0,0),foreground)
st.subheader(header)
st.markdown(description)
st.image(image, use_column_width=True)
return image
def draw_image_stacked(
image: Image,

#draw_image_with_boxes(
# image, classes, labels, boxes, colors, "Bounding Boxes Preview", ""
#)
draw_image_with_semantic_segmentation(
image = draw_image_with_semantic_segmentation(
)
draw_image_with_boxes(
image, classes, labels, boxes, colors, "Bounding Boxes Preview", ""
)

6
com.unity.perception/Editor/Pyrception/pyrception-utils/Dockerfile


FROM python:3.8-slim-buster
COPY . /pyrception-utils
WORKDIR /pyrception-utils
RUN pip install -e .
EXPOSE 8501
ENTRYPOINT pyrception-utils preview --data="."

7
com.unity.perception/Editor/Pyrception/pyrception-utils/Dockerfile.meta


fileFormatVersion: 2
guid: 80f4d8fdbcca0434f8a82af9eb750a60
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存