magenta/note-seq

Permission denied opening temp file

makdaddy48 opened this issue · 2 comments

Hi,

I'm just starting to play with onsets_frames_transcription model from drums. I am attempting to transcribe a single hit of a one-shot sample. While debugging, I can see a temporary file created in C:\Users\micha\AppData\Local\Temp (with zero bytes). However, the process cannot open that file. I'm running Python 3.8.3 under Windows 10. What am I doing wrong?

Thanks.

See below:

(base) C:\Users\micha>onsets_frames_transcription_transcribe --model_dir=E-GMD\e-gmd-v1.0.0\e-gmd_checkpoint --config=drums --load_audio_with_librosa "Tom Wave 3.wav"

2020-10-13 22:26:28.882284: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-10-13 22:26:28.882475: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
c:\programdata\anaconda3\lib\site-packages\librosa\util\decorators.py:9: NumbaDeprecationWarning: ←[1mAn import was requested from a module that has moved location.
Import requested from: 'numba.decorators', please update to use 'numba.core.decorators' or pin to Numba version 0.48.0. This alias will not be present in Numba version 0.50.0.←[0m
from numba.decorators import jit as optional_jit
c:\programdata\anaconda3\lib\site-packages\librosa\util\decorators.py:9: NumbaDeprecationWarning: ←[1mAn import was requested from a module that has moved location.
Import of 'jit' requested from: 'numba.decorators', please update to use 'numba.core.decorators' or pin to Numba version 0.48.0. This alias will not be present in Numba version 0.50.0.←[0m
from numba.decorators import jit as optional_jit
WARNING:tensorflow:From c:\programdata\anaconda3\lib\site-packages\tensorflow\python\compat\v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
WARNING:tensorflow:AutoGraph could not transform <function preprocess_example at 0x000001FD33B21B80> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10) and attach the full output.
Cause: module 'gast' has no attribute 'Index'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
W1013 22:26:33.223956 17772 ag_logging.py:146] AutoGraph could not transform <function preprocess_example at 0x000001FD33B21B80> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10) and attach the full output.
Cause: module 'gast' has no attribute 'Index'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
WARNING:tensorflow:From c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\data.py:134: py_func (from tensorflow.python.ops.script_ops) is deprecated and will be removed in a future version.
Instructions for updating:
tf.py_func is deprecated in TF V2. Instead, there are two
options available in V2.
- tf.py_function takes a python function which manipulates tf eager
tensors instead of numpy arrays. It's easy to convert a tf eager tensor to
an ndarray (just call tensor.numpy()) but having access to eager tensors
means tf.py_functions can use accelerators such as GPUs as well as
being differentiable using a gradient tape.
- tf.numpy_function maintains the semantics of the deprecated tf.py_func
(it is not differentiable, and manipulates numpy arrays). It drops the
stateful argument making all functions stateful.

W1013 22:26:33.223956 17772 deprecation.py:317] From c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\data.py:134: py_func (from tensorflow.python.ops.script_ops) is deprecated and will be removed in a future version.
Instructions for updating:
tf.py_func is deprecated in TF V2. Instead, there are two
options available in V2.
- tf.py_function takes a python function which manipulates tf eager
tensors instead of numpy arrays. It's easy to convert a tf eager tensor to
an ndarray (just call tensor.numpy()) but having access to eager tensors
means tf.py_functions can use accelerators such as GPUs as well as
being differentiable using a gradient tape.
- tf.numpy_function maintains the semantics of the deprecated tf.py_func
(it is not differentiable, and manipulates numpy arrays). It drops the
stateful argument making all functions stateful.

WARNING:tensorflow:AutoGraph could not transform <function input_tensors_to_model_input at 0x000001FD33B22430> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10) and attach the full output.
Cause: module 'gast' has no attribute 'Index'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
W1013 22:26:33.302016 17772 ag_logging.py:146] AutoGraph could not transform <function input_tensors_to_model_input at 0x000001FD33B22430> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10) and attach the full output.
Cause: module 'gast' has no attribute 'Index'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
2020-10-13 22:26:33.343892: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2020-10-13 22:26:33.344098: W tensorflow/stream_executor/cuda/cuda_driver.cc:312] failed call to cuInit: UNKNOWN ERROR (303)
2020-10-13 22:26:33.356562: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-H0T5JPS
2020-10-13 22:26:33.369591: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-H0T5JPS
WARNING:tensorflow:From c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\data.py:656: DatasetV1.output_shapes (from tensorflow.python.data.ops.dataset_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.compat.v1.data.get_output_shapes(dataset).
W1013 22:26:34.879807 17772 deprecation.py:317] From c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\data.py:656: DatasetV1.output_shapes (from tensorflow.python.data.ops.dataset_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.compat.v1.data.get_output_shapes(dataset).
WARNING:tensorflow:From c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\train_util.py:87: The name tf.estimator.tpu.RunConfig is deprecated. Please use tf.compat.v1.estimator.tpu.RunConfig instead.

W1013 22:26:34.973538 17772 module_wrapper.py:136] From c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\train_util.py:87: The name tf.estimator.tpu.RunConfig is deprecated. Please use tf.compat.v1.estimator.tpu.RunConfig instead.

WARNING:tensorflow:From c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\train_util.py:88: The name tf.estimator.tpu.TPUConfig is deprecated. Please use tf.compat.v1.estimator.tpu.TPUConfig instead.

W1013 22:26:34.989150 17772 module_wrapper.py:136] From c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\train_util.py:88: The name tf.estimator.tpu.TPUConfig is deprecated. Please use tf.compat.v1.estimator.tpu.TPUConfig instead.

WARNING:tensorflow:From c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\train_util.py:99: The name tf.estimator.tpu.TPUEstimator is deprecated. Please use tf.compat.v1.estimator.tpu.TPUEstimator instead.

W1013 22:26:35.004811 17772 module_wrapper.py:136] From c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\train_util.py:99: The name tf.estimator.tpu.TPUEstimator is deprecated. Please use tf.compat.v1.estimator.tpu.TPUEstimator instead.

INFO:tensorflow:Using config: {'_model_dir': 'E-GMD\e-gmd-v1.0.0\e-gmd_checkpoint', '_tf_random_seed': None, '_save_summary_steps': 300, '_save_checkpoints_steps': 300, '_save_checkpoints_secs': None, '_session_config': allow_soft_placement: true
graph_options {
rewrite_options {
meta_optimizer_iterations: ONE
}
}
, '_keep_checkpoint_max': None, '_keep_checkpoint_every_n_hours': 1, '_log_step_count_steps': None, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_experimental_max_worker_delay_secs': None, '_session_creation_timeout_secs': 7200, '_service': None, '_cluster_spec': ClusterSpec({}), '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1, '_tpu_config': TPUConfig(iterations_per_loop=300, num_shards=None, num_cores_per_replica=None, per_host_input_for_training=2, tpu_job_name=None, initial_infeed_sleep_secs=None, input_partition_dims=None, eval_training_input_configuration=2, experimental_host_call_every_n_steps=1), '_cluster': None}
I1013 22:26:35.020538 17772 estimator.py:191] Using config: {'_model_dir': 'E-GMD\e-gmd-v1.0.0\e-gmd_checkpoint', '_tf_random_seed': None, '_save_summary_steps': 300, '_save_checkpoints_steps': 300, '_save_checkpoints_secs': None, '_session_config': allow_soft_placement: true
graph_options {
rewrite_options {
meta_optimizer_iterations: ONE
}
}
, '_keep_checkpoint_max': None, '_keep_checkpoint_every_n_hours': 1, '_log_step_count_steps': None, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_experimental_max_worker_delay_secs': None, '_session_creation_timeout_secs': 7200, '_service': None, '_cluster_spec': ClusterSpec({}), '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1, '_tpu_config': TPUConfig(iterations_per_loop=300, num_shards=None, num_cores_per_replica=None, per_host_input_for_training=2, tpu_job_name=None, initial_infeed_sleep_secs=None, input_partition_dims=None, eval_training_input_configuration=2, experimental_host_call_every_n_steps=1), '_cluster': None}
INFO:tensorflow:_TPUContext: eval_on_tpu False
I1013 22:26:35.020538 17772 tpu_context.py:217] _TPUContext: eval_on_tpu False
WARNING:tensorflow:From c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\onsets_frames_transcription_transcribe.py:102: DatasetV1.make_initializable_iterator (from tensorflow.python.data.ops.dataset_ops) is deprecated and will be removed in a future version.
Instructions for updating:
This is a deprecated API that should only be used in TF 1 graph mode and legacy TF 2 graph mode available through tf.compat.v1. In all other situations -- namely, eager mode and inside tf.function -- you can consume dataset elements using for elem in dataset: ... or by explicitly creating iterator via iterator = iter(dataset) and fetching its elements via values = next(iterator). Furthermore, this API is not available in TF 2. During the transition from TF 1 to TF 2 you can use tf.compat.v1.data.make_initializable_iterator(dataset) to create a TF 1 graph mode style iterator for a dataset created through TF 2 APIs. Note that this should be a transient state of your code base as there are in general no guarantees about the interoperability of TF 1 and TF 2 code.
W1013 22:26:35.036062 17772 deprecation.py:317] From c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\onsets_frames_transcription_transcribe.py:102: DatasetV1.make_initializable_iterator (from tensorflow.python.data.ops.dataset_ops) is deprecated and will be removed in a future version.
Instructions for updating:
This is a deprecated API that should only be used in TF 1 graph mode and legacy TF 2 graph mode available through tf.compat.v1. In all other situations -- namely, eager mode and inside tf.function -- you can consume dataset elements using for elem in dataset: ... or by explicitly creating iterator via iterator = iter(dataset) and fetching its elements via values = next(iterator). Furthermore, this API is not available in TF 2. During the transition from TF 1 to TF 2 you can use tf.compat.v1.data.make_initializable_iterator(dataset) to create a TF 1 graph mode style iterator for a dataset created through TF 2 APIs. Note that this should be a transient state of your code base as there are in general no guarantees about the interoperability of TF 1 and TF 2 code.
2020-10-13 22:26:35.057591: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-10-13 22:26:35.073695: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1fd34d77e00 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-10-13 22:26:35.073825: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
INFO:tensorflow:Starting transcription for Tom Wave 3.wav...
I1013 22:26:35.145374 17772 onsets_frames_transcription_transcribe.py:112] Starting transcription for Tom Wave 3.wav...
INFO:tensorflow:Processing file...
I1013 22:26:35.160952 17772 onsets_frames_transcription_transcribe.py:118] Processing file...

c:\programdata\anaconda3\lib\site-packages\librosa\core\audio.py:161: UserWarning: PySoundFile failed. Trying audioread instead.
warnings.warn('PySoundFile failed. Trying audioread instead.')
Exception %s [Errno 13] Permission denied: 'C:\Users\micha\AppData\Local\Temp\tmprlo72l7m.wav'

Traceback (most recent call last):
File "c:\programdata\anaconda3\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\programdata\anaconda3\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "C:\ProgramData\Anaconda3\Scripts\onsets_frames_transcription_transcribe.exe_main
.py", line 7, in
File "c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\onsets_frames_transcription_transcribe.py", line 155, in console_entry_point
tf.app.run(main)
File "c:\programdata\anaconda3\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "c:\programdata\anaconda3\lib\site-packages\absl\app.py", line 300, in run
_run_main(main, args)
File "c:\programdata\anaconda3\lib\site-packages\absl\app.py", line 251, in _run_main
sys.exit(main(argv))
File "c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\onsets_frames_transcription_transcribe.py", line 150, in main
run(argv, config_map=configs.CONFIG_MAP, data_fn=data.provide_batch)
File "c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\onsets_frames_transcription_transcribe.py", line 121, in run
create_example(filename, hparams.sample_rate,
File "c:\programdata\anaconda3\lib\site-packages\magenta\models\onsets_frames_transcription\onsets_frames_transcription_transcribe.py", line 73, in create_example
assert len(example_list) == 1
AssertionError

Edit: I just realized that your issue is in a different file. Try searching for a similar thing related to the temp file in the file that caused the exception.
I had a similar issue too. I fixed it by changing the magenta\lib\site-packages\note_seq\midi_to.py file at around line 210
I removed:

with tempfile.NamedTemporaryFile() as temp_file:
    pretty_midi_object.write(temp_file)
    # Before copying the file, flush any contents
    temp_file.flush()
    # And back the file position to top (not need for Copy but for certainty)
    temp_file.seek(0)
    copyfile(temp_file.name, output_file)

and inserted this code instead:

  temp_file = tempfile.NamedTemporaryFile(delete=False)
  pretty_midi_object.write(temp_file)
  temp_file.flush()
  temp_file.seek(0)
  temp_file.close()
  copyfile(temp_file.name, output_file)
  os.unlink(temp_file.name)

Make sure to import os at the start of the file too.
(I'm new to github so I'm sorry if this isn't the correct format)

Duplicate of #16