Tensorboard can not find the timestamp of the event - python

I can open the website which tensorboard shows me, but there is no data in it, and the cmd says that it can not find the first timestamp of the event.
I type something like this
./tensorboard --logdir=G:/final/log_1
I try many times on win7 and win10 and I am sure that the path is right, but there are no data in that website.
Part of my code
with tf.name_scope('input_layer'):
xs = tf.placeholder(tf.float32, [1, 9],name="x_input")
ys = tf.placeholder(tf.float32, [1, 1],name="y_input")
My code for creating the event file, it will create a file named log_1, and the event files will be in that file
writer = tf.summary.FileWriter(r'log_1/',sess.graph)
writer.close()
I expect the website can show me the graph, however, it showed nothing

1) Firstly, if you are running it on an editor like Jupyter try restarting the kernel.
2) Secondly, I don't know your whole code but one thing you have to do is
merged = tf.summary.merge_all()
summary = sess.run(merged)
writer.add_summary(summary, index)
One problem with your code can be that you are creating all the summary variables but you are not actually adding it to the writer. So before you close it use the above add_summary function. I had the same problem recently and all of the above solved it.

Related

Notebook validation failed Jupyter

This is not a duplicate of Notebook Validation Failed.
I have a Jupyter ntb which was working well until recently. Whatever I do, I am getting those kind of errors which are changing (I'm attaching a few examples) and it does not matter what I do with the ntb (I tried restarting kernel, restarting Jupyter). Also, it is happening ONLY in this ntb, not in others even if run at the same time from the same session. I tried to search but could not find anything. What I get in the Jupyter is:
There are many of those, similar but different:
The save operation succeeded, but the notebook does not appear to be valid. The validation error was:
Notebook validation failed: Non-unique cell id 'geological-poker' detected. Corrected to 'front-hampshire'.:
"<UNKNOWN>"
or others:
Notebook validation failed: Non-unique cell id 'medieval-nebraska' detected. Corrected to 'stock-eating'.:
"<UNKNOWN>"
Notebook validation failed: Non-unique cell id 'intense-award' detected. Corrected to 'blocked-garage'.:
"<UNKNOWN>"
And what I get in the terminal is:
Notebook JSON is invalid: Non-unique cell id 'medieval-nebraska' detected. Corrected to 'convinced-vacation'.
or
Notebook JSON is invalid: Non-unique cell id 'medieval-nebraska' detected. Corrected to 'described-commerce'.
Notebook JSON is invalid: Non-unique cell id 'meaning-victoria' detected. Corrected to 'occasional-numbers'.
Notebook JSON is invalid: Non-unique cell id 'eastern-buyer' detected. Corrected to 'english-benchmark'.
Any idea what's going on and how to fix it?
Update:
It got fixed somehow for a while but then it started doing the same again I still do not get what it was and how it got fixed and ruined again... One fix is to make a copy of the ntb and then discard the old one.
Update 9.10.21:
It looks that this is no more a problem for python v3.8.11. I have not managed to reproduce the issue since updating all packages so probably the easiest fix now is to update. I have:
jupyter core : 4.7.1
jupyter-notebook : 6.4.3
ipython : 7.26.0
ipykernel : 6.2.0
I also happened to find another solution that worked:
First select all the cells in the Jupyter Notebook, then press the "cut/scissors" button (don't panic, at this point your Notebook will be empty), and finally press the "paste" button.
This is from https://github.com/jupyter/notebook/issues/6001#issuecomment-959828688.
I have the same issue and after reading about it, it seems the cause is copy/pasting cells from other notebooks that were created in other sessions. I haven't found a way to fix it, but at least you can prevent it from happening by copying the content of the cells and not the cells themselves.
Simple Answer
STEP 1: Cut all the cells in the Jupyter-notebook using scissor option as shown.
STEP 2: Save the notebook now, and paste back the cells cut in the previous step using paste option as shown.
STEP 3: Save again and your bug should be fixed now! Hurry, Happy coding.
Code to resave a notebook with the cell name issue resolved:
import nbformat as nbf
from glob import glob
import uuid
def get_cell_id(id_length=8):
return uuid.uuid4().hex[:id_length]
# -- SETUP
nb_name = 'my_notebook'
# -- MAIN
# grab notebook
notebooks = list(filter(lambda x: nb_name in x, glob("./*.ipynb", recursive=True)))
# iterate over notebooks
for ipath in sorted(notebooks):
# load notebook
ntbk = nbf.read(ipath, nbf.NO_CONVERT)
cell_ids = []
for cell in ntbk.cells:
cell_ids.append(cell['id'])
# reset cell ids if there are duplicates
if not len(cell_ids) == len(set(cell_ids)):
for cell in ntbk.cells:
cell['id'] = get_cell_id()
nbf.write(ntbk, ipath)
Source: https://github.com/jupyter/notebook/issues/6001#issuecomment-856303981

Plot Over Line with pvpython

Good afternoon,
I am trying to use the filter "Plot Over Line" of Paraview in a Python script. Basically, I want to:
Open the file ".vtu";
Use the filter PlotOverLine for the velocity;
Save the data in a ".csv" file.
On internet, I found a possible way to do this, but it gives error if ran with pvpython (even if using the word "simple" before the commands):
from paraview import simple
import csv
flow = GetActiveSource()
plotOverLine1 = PlotOverLine(Input=flow, Source='High Resolution Line Source')
passArrays1 = PassArrays(Input=plotOverLine1)
passArrays1.PointDataArrays = ['U']
plotOverLine1.Source.Point1 = [0, 0, 0]
plotOverLine1.Source.Point2 = [0, 0.4, 0]
writer = CreateWriter('data.csv')
writer.UpdatePipeline()
First, you may report here you errors.
As you suggest, your script cannot work as is, you should change the import to from paraview.simple import *.
Also, your writer does not have explicit input. I recommend to use CreateWriter(filename='path', input=myInput), or, for a one shot write, SaveData(filename='path', input=myInput).
Finally, one way to produce such scripts is to use Tools / Start Trace menu option (with the default config). Then perform actions in the interface. Finally Tools / Stop Trace give you the python script corresponding to your actions.

How to write image data to tensorboard without opening new categories

I wrote a Keras/Tensorflow callback that writes a confusion matrix to the Images tab in Tensorboard. This worked fine in TF 2.1. Unfortunately I had to convert it to TF 1.14, as other packages depend on this version.
Everything works fine (more or less), except for the Tensorboard Reports.
The Problem
As you can see in the screenshot below, there are many categories(? tags? channels? I am not sure about the terminology) instead of only one.
screenshot: multiple categories for images
Seemingly correlated to this issue, the training scalars like "val_loss" only plot the first datapoint and nothing afterwards. See second screenshot
screenshot: scalars showing one data point
Also, Tensorboard is printing the following error:
File <path/to/event-file> updated even though the current file is <path/to/new-event-file>
So I assume somehow my TF FileWriters are disagreeing on where to write.
Regarding the Confusion Matrix Callback: The writing function looks like this:
def _figure_to_summary(self, fig, step):
# attach a new canvas if not exists
if fig.canvas is None:
matplotlib.backends.backend_agg.FigureCanvasAgg(fig)
fig.canvas.draw()
w, h = fig.canvas.get_width_height()
img = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
img = img.reshape((1, h, w, 3))
with K.get_session().as_default():
tensor = tf.constant(img)
image = tf.summary.image(self.title, tensor).eval()
self._summary_writer.add_summary(image, global_step=step)
self._summary_writer.flush()
With fig being the matplot figure of the Confusion Matrix and step as an int, which should enable Tensorboard to add the little slider over the image to show the history of the matrix.
The model is trained as follows:
run_id = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
tb_path = os.path.join("tensor/", run_id)
tb_reporter = TensorBoard(tb_path)
summ_wr = FileWriter(tb_path)
conf_matr = ConfusionMatrix(va, TARGET_CLASSES.keys(), summ_wr, normalize=True)
cb_list = [tb_reporter, conf_matr]
model.fit(tr, epochs=500, validation_data=va, callbacks=cb_list)
Where summ_wr becomes self._summary_writer of the callback.
What I tried
I only tried changing the way the summary is written. Trying tf.merge_all(), opening, closing and reopening the FileWriter in various combinations, but nothing changed. When I deactivate the custom callback, the Tensorboard callback works as expected.
My Questions
How can I write Image Data into the same category every time?
Will the image get the scrollbar?
How can I fix the problem, that the Keras Tensorboard callback does not show its data?
I assume all the problems are related and solving one results in solving all of them, but I am completely stumped on how to do it.
I am thankful for any suggestions :)
Edit:
I just found this question: Tensorboard Image Summaries
This seems to solve the problem, unfortunately the answer does not have a lot of context, so I don't how to integrate the solution into the code.
The solution I found consists of two parts.
First: I stole the FileWriter from the Tensorboard Callback from keras. Tensorboard.writer contains the FileWriter after set_model has been called.
Second: The Summary must be created via the constructor and be passed the tag-keyword. This forces the images into the same group and the writers do not interfere with each other.
I found the second part of the solution here: TensorBoard: How to write images to get a steps slider?

PowerBI is not passing over the datafield to the Python script

I am trying to run a simple Python script in PowerBI to get it working but it only comes up with many errors.I have tried to:
reinstall Numpy and Matplotlib.
tried using Python 3.5 and 3.6
Uninstall Conda and reinstall
I have a screen shot showing my issue (it all fits on one screen bellow). The data is just a,b,c and 1,2,3 for x and y labeled "Label" and "Data".
Screen shot of error and code
Code here:
# The following code to create a dataframe and remove duplicated rows is always executed and acts as
a preamble for your script:
dataset = pandas.DataFrame(Data, Label)
# dataset = dataset.drop_duplicates()
# Paste or type your script code here:
import matplotlib.pyplot as plt
dataset.plot(kind='scatter', x='Label', y='Data', color='red')
plt.show()
You need to comment out the following:
dataset = pandas.DataFrame(Data, Label)
Even though it is 'commented out' it will run. It just sets up the data frame ready for the visual, here is a none working example, were it isn't commented out:
Hope that helps

Python Movie.py error on writing more than 4 videos

I've been trying to figure out this problem the entire day. I'm trying to add a image at the bottom of every video in a directory.
Here is the error that i get after writing just 4 videos out of 100
del self.reader
AttributeError: reader
Exception ignored in: <bound method VideoFileClip.__del__ of <moviepy.video.io.VideoFileClip.VideoFileClip object at 0x03D787B0>>
Here is how im trying to write the video
video = CompositeVideoClip([clip1, clip2.set_duration(clip1.duration)])
video = CompositeVideoClip("mixclip"+random.randint(999,999999)"+.mp4")
del video
del clip1
del clip2
Edit: Posted a slightly wrong code which i made while i was testing and got a instant a -1. Changed it. But i still cannot find solution to this problem.
Edit2: Tested alot and figured it out. Fixed it by declaring clip2 duration before mixing it. Rewrote entire code didn't check what other changes i made but its working as intended now.
Update to the latest version at the GitHub repo or wait until the next moviepy update is pushed to PyPI, where this is fixed. (See these commits: one, two)
However, unless you tell us what the line
video = CompositeVideoClip("mixclip"+random.randint(999,999999)"+.mp4")
means, you may be coming across an underlying problem with your usage.
Just a side note: the above line has a couple of errors; change it to this:
video = CompositeVideoClip("mixclip" + str(random.randint(999, 999999)) + ".mp4")

Categories