I am running a model using tqdm.notebook to check the progress using python3.8. However, the progress bar is not running though the generation works okay.
It just shows this on and on.
Here is my following code, and the model I'm running.
import numpy as np
import tensorflow as tf
from midi_ddsp.utils.midi_synthesis_utils import synthesize_mono_midi, conditioning_df_to_audio
from midi_ddsp.utils.inference_utils import get_process_group
from midi_ddsp.midi_ddsp_synthesize import load_pretrained_model
from midi_ddsp.data_handling.instrument_name_utils import INST_NAME_TO_ID_DICT
from tqdm.notebook import tqdm
# -----MIDI Synthesis-----
midi_file = '/Users/midi-ddsp/midi_example/ode_to_joy.mid'
# Load pre-trained model
synthesis_generator, expression_generator = load_pretrained_model()
# Synthesize with violin:
instrument_name = 'violin'
instrument_id = INST_NAME_TO_ID_DICT[instrument_name]
# Run model prediction
midi_audio, midi_control_params, midi_synth_params, conditioning_df = synthesize_mono_midi(synthesis_generator,
expression_generator,
midi_file, instrument_id,
output_dir=None)
synthesized_audio = midi_audio # The synthesized audio
conditioning_df_changed = conditioning_df.copy()
idk what's the problem. Hope someone can tell me. I appreciate it!
Related
I am trying to run the following code:
from pm4py.algo.discovery.alpha import factorial as alpha_miner
from pm4py.objects.log.importer.xes import factory as xes_importer
event_log = xes_importer.import_log(os.path.join("tests","input_data","running-example.xes"))
net, initial_marking, final_marking = alpha_miner.apply(event_log)
gviz = pn_vis_factory.apply(net, initial_marking, final_marking)
pn_vis_factory.view(gviz)
However, when I run the alpha miner, I get an error message that factory cannot be imported.
What could be the reason or does anyone know a soulution for this?
Many thanks for the answer
from pm4py.algo.discovery.alpha import algorithm as alpha_miner
Find all process discoveries and its information at:
https://pm4py.fit.fraunhofer.de/documentation#discovery
Try this:
import os
# Alpha Miner
from pm4py.algo.discovery.alpha import algorithm as alpha_miner
# XES Reader
from pm4py.objects.log.importer.xes import importer as xes_importer
# Visualize
from pm4py.visualization.petri_net import visualizer as pn_visualizer
log = xes_importer.apply(os.path.join("tests","input_data","running-example.xes"))
net, initial_marking, final_marking = alpha_miner.apply(log)
gviz = pn_visualizer.apply(net, initial_marking, final_marking)
pn_visualizer.view(gviz)
I am new on using Detectron2. I want to load the video from local drive. And then, do detection using my trained model using Detectron2's VideoVisualizer.
I tried to find a tutorial about this. But it does not exist. Could you please what do I do?
Thank you
import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()
# import some common libraries
import numpy as np
import tqdm
import cv2
# import some common detectron2 utilities
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
from detectron2.utils.video_visualizer import VideoVisualizer
from detectron2.utils.visualizer import ColorMode, Visualizer
from detectron2.data import MetadataCatalog
import time
video = cv2.VideoCapture('gdrive/My Drive/video.mp4')
width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.OUTPUT_DIR = 'gdrive/My Drive/mask_rcnn/'
cfg.MODEL.WEIGHTS = os.path.join(cfg.OUTPUT_DIR, "model_final.pth")
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.7 # set threshold for this model
predictor = DefaultPredictor(cfg)
v = VideoVisualizer(MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), ColorMode.IMAGE)
First, check the following tutorial (you can skip training parts if you don't want to train on your own data).
https://colab.research.google.com/drive/16jcaJoc6bCFAQ96jDe2HwtXj7BMD_-m5#scrollTo=Vk4gID50K03a
Then, look at the following code to inference on video.
https://github.com/facebookresearch/detectron2/blob/master/demo/demo.py
I'm trying to write my own chatbot with the RASA framework.
Right now I'm just playing around with it and I have the following piece of code for training purposes.
from rasa.nlu.training_data import load_data
from rasa.nlu.config import RasaNLUModelConfig
from rasa.nlu.model import Trainer
from rasa.nlu import config
training_data = load_data("./data/nlu.md")
trainer = Trainer(config.load("config.yml"))
interpreter = trainer.train(training_data)
model_directory = trainer.persist("./models/nlu",fixed_model_name="current")
Now, I read that if I wanted to test it I should do something like this.
from rasa.nlu.evaluate import run_evaluation
run_evaluation("nlu.md", model_directory)
But this code is not available anymore in rasa.nlu.evaluate nor in rasa.nlu.test!
What's the way, then, of testing a RASA model?
The module was renamed.
Please import
from rasa.nlu.test import run_evaluation
Alternatively you now also do
from rasa.nlu import test
test_result = test(path_to_test_data, unpacked_model)
intent_evaluation_report = test_result["intent_evaluation"]["report"]
print(intent_evaluation_report)
I am using the data from the following Kaggle competition to train Random Forest on Tensorflow - https://www.kaggle.com/c/santander-product-recommendation
The code was working fine a day ago but now whenever I run the training code for the Random Forest: I get the following message (This is not an error message on the code but for the jupyter kernel):
The kernel appears to have died. It will restart automatically.
I am using the following code:
import tensorflow as tf
import numpy as np
import pandas as pd
import math
import os
from glob import glob
import google.datalab.bigquery as bq
print('Libraries Imported')
trainingdata = bq.Query('SELECT * FROM `kagglesantander.training`')
train_dataset = trainingdata.execute(output_options=bq.QueryOutput.dataframe()).result()
print('Train Data Fetched')
X = train_dataset.iloc[:,1:-1]
y = train_dataset.iloc[:,-1]
x_train = X.astype(np.float32).values
y_train = y.astype(np.float32).values
print('Data Prepared')
params = tf.contrib.tensor_forest.python.tensor_forest.ForestHParams(
num_classes=1, num_features=369, num_trees = 10).fill()
print("Params =")
print(vars(params))
# Remove previous checkpoints so that we can re-run this step if necessary.
for f in glob("./ModelTrain/*"):
os.remove(f)
classifier = tf.contrib.tensor_forest.client.random_forest.TensorForestEstimator(
params, model_dir="./ModelTrain/")
classifier.fit(x=x_train, y=y_train)
print('Forest Trained')
The error is happening due to the line:
classifier.fit(x=x_train, y=y_train)
As I tried the code without the line and it was working fine
I've been experiencing some odd issues with randomness in scikit-learn on my macbook. (OS X 10.12.6, conda environment with python 2.7). As a test, I've set up the following script:
import numpy.random as npr
import numpy.testing as npt
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_breast_cancer
def test_randomness_one():
npr.seed(54)
rand_ints_one = npr.randint(500, size=50)
npr.seed(54)
rand_ints_two = npr.randint(500, size=50)
npt.assert_array_equal(rand_ints_one, rand_ints_two)
def test_logit_one():
data = load_breast_cancer()
preds_one = LogisticRegression(random_state=2)\
.fit(data['data'], data['target'])\
.decision_function(data['data'])
preds_two = LogisticRegression(random_state=2)\
.fit(data['data'], data['target'])\
.decision_function(data['data'])
npt.assert_array_equal(preds_one, preds_two)
def test_logit_two():
data = load_breast_cancer()
preds_one = LogisticRegression()\
.fit(data['data'], data['target'])\
.decision_function(data['data'])
preds_two = LogisticRegression()\
.fit(data['data'], data['target'])\
.decision_function(data['data'])
npt.assert_array_equal(preds_one, preds_two)
# A note: main used for testing with the interpreter directly
# Executed with pytest *without* the below lines.
if __name__ == "__main__":
test_randomness_one()
test_logit_one()
test_logit_two()
In theory, all of these results should be identical, and coworkers running Ubuntu and windows boxes have verified this. On my box, all of these tests pass if executed in a REPL or run via python toy_test.py. If run via pytest toy_test.py, however, test_logit_one fails consistently and test_logit_two fails often but not always. Where is the randomness coming from in this situation? Is it OS-level? conda-level? pytest? Or something else?