Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PermissionError: [Errno 13] Permission denied on Windows #5762

Open
SamedHrmn opened this issue Dec 1, 2024 · 3 comments
Open

PermissionError: [Errno 13] Permission denied on Windows #5762

SamedHrmn opened this issue Dec 1, 2024 · 3 comments
Assignees
Labels
os:windows MediaPipe issues on Windows platform:python MediaPipe Python issues type:modelmaker Issues related to creation of custom on-device ML solutions type:support General questions

Comments

@SamedHrmn
Copy link

SamedHrmn commented Dec 1, 2024

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

Yes

OS Platform and Distribution

Windows 10

Python Version

3.10

MediaPipe Model Maker version

0.2.1.4

Task name (e.g. Image classification, Gesture recognition etc.)

Face stylization

Describe the actual behavior

Model wasnt initializing

Describe the expected behaviour

Model creating succesfully

Standalone code/steps you may have used to try to get what you need

Hi, Im trying to make retrain model using face-stylization guide on site. Colab notebook was working but I want to run code on my Windows machine. However I installed mediapipe_model_maker latest version without tensorflow-text (I found out that it is incompatible with Windows). However, the model gives an error somewhere while downloading the necessary files. I even changed the temp folder path in the package source code, but it didn't work. I don't think there is a problem with file privileges in Windows because I also started Pycharm as an administrator.

Guide: https://ai.google.dev/edge/mediapipe/solutions/customization/face_stylizer

Other info / Complete Logs

Here main.py (pseudo):

from mediapipe_model_maker import face_stylizer
from mediapipe_model_maker import image_utils
from mediapipe_model_maker.python.core.utils.loss_functions import PerceptualLossWeight
import cv2
import tensorflow as tf

face_stylizer_options = face_stylizer.FaceStylizerOptions(
    model=face_stylizer.SupportedModels.BLAZE_FACE_STYLIZER_256,
    model_options=face_stylizer.ModelOptions(swap_layers=[8, 9, 10],
                                             adv_loss_weight=0.1,
                                             perception_loss_weight=PerceptualLossWeight(l1=0.05,
                                                                                         content=0.4,
                                                                                         style=0.5)),
    hparams=face_stylizer.HParams(
        learning_rate=5e-4,
        epochs=100,
        batch_size=2,

    )
)

face_stylizer_model = face_stylizer.FaceStylizer.create(
        train_data=data, options=face_stylizer_options
    )

Logs:

C:\myproje\.venv\Scripts\python.exe C:\myproje\main.py 
2024-12-01 23:06:02.458393: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
WARNING:tensorflow:From C:\myproje\.venv\lib\site-packages\keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.

Using existing files at C:\myproje\Temp\model_maker\face_stylizer\face_landmarker_v2.task
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
W0000 00:00:1733083567.276676   16408 inference_feedback_manager.cc:114] Feedback manager requires a model with a single signature inference. Disabling support for feedback tensors.
WARNING:tensorflow:From C:\myproje\.venv\lib\site-packages\mediapipe_model_maker\python\vision\face_stylizer\dataset.py:40: The name tf.logging.info is deprecated. Please use tf.compat.v1.logging.info instead.

W0000 00:00:1733083567.544642   12816 landmark_projection_calculator.cc:186] Using NORM_RECT without IMAGE_DIMENSIONS is only supported for the square ROI. Provide IMAGE_DIMENSIONS or use PROJECTION_MATRIX.
2024-12-01 23:06:07.546489: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE SSE2 SSE3 SSE4.1 SSE4.2 AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Downloading https://storage.googleapis.com/mediapipe-assets/face_stylizer_encoder.tar.gz to C:\myproje\Temp\model_maker\face_stylizer\encoder
Traceback (most recent call last):
  File "C:\myproje\main.py", line 48, in <module>
    model = train_stylizer()
  File "C:\myproje\main.py", line 27, in train_stylizer
    face_stylizer_model = face_stylizer.FaceStylizer.create(
  File "C:\myproje\.venv\lib\site-packages\mediapipe_model_maker\python\vision\face_stylizer\face_stylizer.py", line 104, in create
    face_stylizer._create_and_train_model(train_data)
  File "C:\myproje\.venv\lib\site-packages\mediapipe_model_maker\python\vision\face_stylizer\face_stylizer.py", line 146, in _create_and_train_model
    self._create_model()
  File "C:\myproje\.venv\lib\site-packages\mediapipe_model_maker\python\vision\face_stylizer\face_stylizer.py", line 152, in _create_model
    constants.FACE_STYLIZER_ENCODER_MODEL_FILES.get_path()
  File "C:\myproje\.venv\lib\site-packages\mediapipe_model_maker\python\core\utils\file_util.py", line 74, in get_path
    tarf = tarfile.open(tempf.name)
  File "C:\Python310\lib\tarfile.py", line 1613, in open
    return func(name, "r", fileobj, **kwargs)
  File "C:\Python310\lib\tarfile.py", line 1679, in gzopen
    fileobj = GzipFile(name, mode + "b", compresslevel, fileobj)
  File "C:\Python310\lib\gzip.py", line 174, in __init__
    fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
PermissionError: [Errno 13] Permission denied: 'C:\\myproje\\Temp\\tmpevzocum2.tar.gz'
@SamedHrmn SamedHrmn added the type:modelmaker Issues related to creation of custom on-device ML solutions label Dec 1, 2024
@google-ml-butler google-ml-butler bot added the type:support General questions label Dec 1, 2024
@kalyan2789g kalyan2789g added os:windows MediaPipe issues on Windows platform:python MediaPipe Python issues labels Dec 2, 2024
@kalyan2789g
Copy link
Collaborator

Hi @SamedHrmn ,
We are actively working on resolving this issue and will keep you informed of any developments.
Thanks,
@kalyan2789g

@kalyan2789g
Copy link
Collaborator

Hi @SamedHrmn,
We have attempted to replicate the issue on our end, but unfortunately, we were unable to reproduce the specific issue you described. To better understand the problem, we kindly request you to provide additional context or detailed steps to reproduce the issue. This information will greatly aid our analysis process.
Thanks,
@kalyan2789g

@kalyan2789g kalyan2789g added the stat:awaiting response Waiting for user response label Dec 11, 2024
@SamedHrmn
Copy link
Author

Okey, Im going to step by step, firstly I installed this requirements.txt on Python 3.10 .venv (PyCharm 2024.3.1 -Community Edition)

absl-py
mediapipe>=0.10.0
numpy<2
opencv-python
tensorflow>=2.10,<2.16
tensorflow-addons
tensorflow-datasets
tensorflow-hub
tensorflow-model-optimization<0.8.0
Cython
google-api-python-client>=1.6.7
kaggle>=1.3.9
oauth2client
opencv-python-headless
pandas>=0.22.0
py-cpuinfo>=3.3.0
pycocotools
sacrebleu
seqeval
tf-slim>=1.1.0
pyyaml
gin-config

After completed, run these on terminal:

- pip install mediapipe-model-maker==0.2.1.4 --no-deps
- pip install tf-models-official==2.15.0 --no-deps

After that, make comment this line in init.py from mediapipe_model_maker module

from mediapipe_model_maker.python.vision.core import image_utils
from mediapipe_model_maker.python.core.utils import quantization
from mediapipe_model_maker.python.core.utils import model_util

from mediapipe_model_maker.python.vision import image_classifier
from mediapipe_model_maker.python.vision import gesture_recognizer
##from mediapipe_model_maker.python.text import text_classifier ------> Comment this  because unsupported on windows
from mediapipe_model_maker.python.vision import object_detector
from mediapipe_model_maker.python.vision import face_stylizer

Now, I can run main.py file:

from mediapipe_model_maker import face_stylizer
from mediapipe_model_maker import image_utils
from mediapipe_model_maker.python.core.utils.loss_functions import PerceptualLossWeight
import cv2
import tensorflow as tf

style_image_path = "C:\\Users\\samed\\PycharmProjects\\face_stylization\\art.png"

data = face_stylizer.Dataset.from_image(filename=style_image_path)

face_stylizer_options = face_stylizer.FaceStylizerOptions(
    model=face_stylizer.SupportedModels.BLAZE_FACE_STYLIZER_256,
    model_options=face_stylizer.ModelOptions(swap_layers=[8, 9, 10],
                                             adv_loss_weight=0.1,
                                             perception_loss_weight=PerceptualLossWeight(l1=0.05,
                                                                                         content=0.4,
                                                                                         style=0.5)),
    hparams=face_stylizer.HParams(
        learning_rate=5e-4,
        epochs=100,
        batch_size=2,

    )
)

def train_stylizer():
    face_stylizer_model = face_stylizer.FaceStylizer.create(
        train_data=data, options=face_stylizer_options
    )

    return face_stylizer_model
def eval_performance(face_stylizer_model):
    print('Input style image')
    style_image_tensor = image_utils.load_image(style_image_path)
    style_cv_image = cv2.cvtColor(style_image_tensor.numpy(), cv2.COLOR_RGB2BGR)
    resized_style_cv_image = cv2.resize(style_cv_image, (256, 256))
    cv2.imshow("Style Input",resized_style_cv_image)

    eval_output = face_stylizer_model.stylize(data)
    eval_output_data = eval_output.gen_tf_dataset()
    iterator = iter(eval_output_data)

    reconstruct_style_image = (tf.squeeze(iterator.get_next()).numpy())
    test_output_image = cv2.cvtColor(reconstruct_style_image, cv2.COLOR_RGB2BGR)
    print('\nReconstructed style image')
    cv2.imshow("Reconstructed",test_output_image)

model = train_stylizer()
eval_performance(model)

Here all logs after running main.py:

C:\myproje2\.venv\Scripts\python.exe C:\myproje2\main.py 
2024-12-15 13:59:18.289222: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
WARNING:tensorflow:From C:\myproje2\.venv\lib\site-packages\keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.

Using existing files at C:\Users\samed\AppData\Local\Temp\model_maker\face_stylizer\face_landmarker_v2.task
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
W0000 00:00:1734260363.815427    4508 inference_feedback_manager.cc:114] Feedback manager requires a model with a single signature inference. Disabling support for feedback tensors.
WARNING:tensorflow:From C:\myproje2\.venv\lib\site-packages\mediapipe_model_maker\python\vision\face_stylizer\dataset.py:40: The name tf.logging.info is deprecated. Please use tf.compat.v1.logging.info instead.

2024-12-15 13:59:24.138582: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE SSE2 SSE3 SSE4.1 SSE4.2 AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Downloading https://storage.googleapis.com/mediapipe-assets/face_stylizer_encoder.tar.gz to C:\Users\samed\AppData\Local\Temp\model_maker\face_stylizer\encoder
Traceback (most recent call last):
  File "C:\myproje2\main.py", line 48, in <module>
    model = train_stylizer()
  File "C:\myproje2\main.py", line 27, in train_stylizer
    face_stylizer_model = face_stylizer.FaceStylizer.create(
  File "C:\myproje2\.venv\lib\site-packages\mediapipe_model_maker\python\vision\face_stylizer\face_stylizer.py", line 104, in create
    face_stylizer._create_and_train_model(train_data)
  File "C:\myproje2\.venv\lib\site-packages\mediapipe_model_maker\python\vision\face_stylizer\face_stylizer.py", line 146, in _create_and_train_model
    self._create_model()
  File "C:\myproje2\.venv\lib\site-packages\mediapipe_model_maker\python\vision\face_stylizer\face_stylizer.py", line 152, in _create_model
    constants.FACE_STYLIZER_ENCODER_MODEL_FILES.get_path()
  File "C:\myproje2\.venv\lib\site-packages\mediapipe_model_maker\python\core\utils\file_util.py", line 74, in get_path
    tarf = tarfile.open(tempf.name)
  File "D:\Python310\lib\tarfile.py", line 1632, in open
    return func(name, "r", fileobj, **kwargs)
  File "D:\Python310\lib\tarfile.py", line 1698, in gzopen
    fileobj = GzipFile(name, mode + "b", compresslevel, fileobj)
  File "D:\Python310\lib\gzip.py", line 174, in __init__
    fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\samed\\AppData\\Local\\Temp\\tmpofffbzuu.tar.gz'

Process finished with exit code 1

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Waiting for user response label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os:windows MediaPipe issues on Windows platform:python MediaPipe Python issues type:modelmaker Issues related to creation of custom on-device ML solutions type:support General questions
Projects
None yet
Development

No branches or pull requests

2 participants