Temporal Attention on Varaiable Length Input? - deep-learning

I'm having trouble implementing the code. I would to ask for your guidance. Here is the query:
KerasTensor(type_spec=TensorSpec(shape=(None, None, 64), dtype=tf.float32, name=None), name='gru_1/transpose_2:0', description="created by layer 'gru_1'")
first "None" is Batch size
Second "None" is Time stamps
third is "GRU" cell dimensions
Now I want to apply temporal attention on this tensor variable. Please note that "time stamps" as "None" creating problem.

Related

About input_shape in keras.layers from tensorflow

I am a beginner for tensorflow. I had just tried to fit a simple LeNet-5 for mnist data.
My training and test data are first in Numpy format. i.e., (60000, 28, 28). Then I set my model as below.
model_LeNet5 = Sequential([
layers.Conv2D(6, kernel_size=3, strides=1, input_shape=(28, 28, 1)),
layers.MaxPooling2D(pool_size=2,strides=2),
layers.ReLU(),
layers.Conv2D(16,kernel_size=3,strides=1),
layers.MaxPooling2D(pool_size=2,strides=2),
layers.ReLU(),
layers.Flatten(),
layers.Dense(120, activation='relu'),
layers.Dense(84, activation='relu'),
layers.Dense(10)
])
I could understand that I get success when I set input_shape as (28,28) or train_images.shape[1:], but I can not understand that input_shape = (28,28,1) is also worked (shown as code above).
It seems that there is an inconsistancy between the shape of data and setting of input size (i.e., [60000,28,28] vs [28,28,1]). Also the broadcast rule may not link [60000,28,28] with [28,28,1].
Thanks for anyone who will explain the mechanism of input_shape.
A single grayscale image can be represented using a two-dimensional (2D) NumPy array or a tensor. Since there is only one channel in a grayscale image, we don’t need an extra dimension to represent the color channel. The two dimensions represent the height and width of the image.
A batch of 3 grayscale images can be represented using a three-dimensional (3D) NumPy array or a tensor. Here, we need an extra dimension to represent the number of images.
For more information, check out this article on towardsdatascience.

How to set the horizontal (or vertical) axis number format for a Google Sheets chart?

I'm generating a spreadsheet, several pivot tables, and charts to visualize the results. I have everything working, except I haven't found a way to set the number format for the chart horizontal/vertical axes. I want the axes to show whole numbers, without the need for me to change the number format of the backing data.
Unfortunately, the documentation provided by Google does not cover this feature: https://developers.google.com/apps-script/chart-configuration-options#line-chart-configuration-options.
It is possible to set the number format manually, however, as I'm generating a large number of charts, it would be too burdensome to do this for all charts.
Here is an example of the Apps Script code used to generate my charts:
embeddedChartBuilder.setChartType(Charts.ChartType.LINE)
.setPosition(chartRow, chartColumn, 0, 0)
.setNumHeaders(1)
.setOption('backgroundColor', '#222222')
.setOption('height', chartHeightPx)
.setOption('width', chartWidthPx)
.setOption('series', [
{color:'#4ebcbb', pointSize:6, lineWidth:4},
{color:'#cccccc', pointSize:6, lineWidth:4},
{color:'#666666', pointSize:6, lineWidth:4},
{color:'#34a853', pointSize:6, lineWidth:4}])
.setOption('applyAggregateData', 0)
.setOption('vAxis.gridlines.color', '#434343')
.setOption('vAxis.minValue', 0)
.setOption('vAxis.maxValue', 5)
.setOption('vAxis.textStyle', { color: '#efefef', fontName: 'Arial', fontSize: 12, bold: false, italic: false })
.setOption('hAxis.textStyle', { color: '#efefef', fontName: 'Arial', fontSize: 12, bold: false, italic: false });
On the Line Chart page under Configuration Options you have the hAxis.format with the following description:
A format string for numeric or date axis labels.
For number axis labels, this is a subset of the decimal formatting ICU pattern set . For instance, {format:'#,###%'} will display values "1,000%", "750%", and "50%" for values 10, 7.5, and 0.5. You can also supply any of the following:
{format: 'none'}: displays numbers with no formatting (e.g., 8000000)
{format: 'decimal'}: displays numbers with thousands separators (e.g., 8,000,000)
{format: 'scientific'}: displays numbers in scientific notation (e.g., 8e6)
{format: 'currency'}: displays numbers in the local currency (e.g., $8,000,000.00)
{format: 'percent'}: displays numbers as percentages (e.g., 800,000,000%)
{format: 'short'}: displays abbreviated numbers (e.g., 8M)
{format: 'long'}: displays numbers as full words (e.g., 8 million)
For date axis labels, this is a subset of the date formatting ICU pattern set . For instance, {format:'MMM d, y'} will display the value "Jul 1, 2011" for the date of July first in 2011.
The actual formatting applied to the label is derived from the locale the API has been loaded with. For more details, see loading charts with a specific locale .
In computing tick values and gridlines, several alternative combinations of all the relevant gridline options will be considered and alternatives will be rejected if the formatted tick labels would be duplicated or overlap. So you can specify format:"#" if you want to only show integer tick values, but be aware that if no alternative satisfies this condition, no gridlines or ticks will be shown.
This option is only supported for a continuous axis.
Type: string
Default: auto
And also a vAxis.format option with the following formats:
A format string for numeric axis labels. This is a subset of the ICU pattern set . For instance, {format:'#,###%'} will display values "1,000%", "750%", and "50%" for values 10, 7.5, and 0.5. You can also supply any of the following:
{format: 'none'}: displays numbers with no formatting (e.g., 8000000)
{format: 'decimal'}: displays numbers with thousands separators (e.g., 8,000,000)
{format: 'scientific'}: displays numbers in scientific notation (e.g., 8e6)
{format: 'currency'}: displays numbers in the local currency (e.g., $8,000,000.00)
{format: 'percent'}: displays numbers as percentages (e.g., 800,000,000%)
{format: 'short'}: displays abbreviated numbers (e.g., 8M)
{format: 'long'}: displays numbers as full words (e.g., 8 million)
The actual formatting applied to the label is derived from the locale the API has been loaded with. For more details, see loading charts with a specific locale .
In computing tick values and gridlines, several alternative combinations of all the relevant gridline options will be considered and alternatives will be rejected if the formatted tick labels would be duplicated or overlap. So you can specify format:"#" if you want to only show integer tick values, but be aware that if no alternative satisfies this condition, no gridlines or ticks will be shown.
Type: string
Default: auto

How to visualize 3d joints of a SMPL model based on pose params

I am trying to use demo.py in nkolot
/
GraphCMR | GitHub. I am interested in obtaining joints from the inferred SMPL image and visualize it similar to described in README of this project: gulvarol
/
smplpytorch | GitHub.
I also posted the issue here: https://github.com/nkolot/GraphCMR/issues/36.
What I tried that didn't work.
I changed https://github.com/nkolot/GraphCMR/blob/4e57dca4e9da305df99383ea6312e2b3de78c321/demo.py#L118 to
pred_vertices, pred_vertices_smpl, pred_camera, smpl_pose, smpl_shape = model(...) to get smpl_pose (of shape torch.Size([1, 24, 3, 3])). Then I just flattened it by doing smpl_pose.cpu().data.numpy()[:, :, :, -1].flatten('C').reshape(1, -1) and used the resulting (1, 72) pose params as input in pose_params variable of smplpytorch demo.
The resulting visualization doesn't look correct to me. Is this the right approach? Perhaps there is an easier way to do what I am doing.
How to get 3d joints from demo.py and visualize it | nkolot
/
GraphCMR
The problem is that
smpl_pose (of shape torch.Size([1, 24, 3, 3]))
is the SMPL pose parameters expressed as a rotation matrix.
You need to make a transformation from rotation matrix to axis-angle representation which is (72,1). You can use Rodrigues formula to do it, as claimed in the paper:
Get more information from the paper:
SMPL: A Skinned Multi-Person Linear Model

Simulink Matlab function block deleting rows from a vector

That i want to do is to delete certain rows (or columns doesn't really mater...) from a given vector.
By going through Simulink's components found out that there is nothing performing such an operation,there are blocks help one add elements but nothing clearly for removing,so ended up trying to delete them by using a function block and following the online examples that demonstrate the usage of "[]".Lets say that i want to delete the second column of the vector u,i do u(:, 2) = [];.
That works absolutely fine in a separate m file or function but unfortunately not in a function block returning:
"Simulink does not have enough information to determine output sizes for
this block. If you think the errors below are inaccurate, try specifying
types for the block inputs and/or sizes for the block outputs."
and:
Size mismatch (size [4 x 4] ~= size [4 x 3]).
The size to the left is the size of the left-hand side of the assignment.
Function 'MATLAB Function' (#107.41.42), line 4, column 1:
"u"
Launch diagnostic report.
Is there any alternative you can suggest to remove several elements in a given vector in Simulink?
Thanks in advance
George
Finally,managed to do it without function block.There is a much easier way,by using Pad,and defining the output vector to be shorter than the input resulting in truncation.

Matplotlib/Pyplot: How to zoom subplots together?

I have plots of 3-axis accelerometer time-series data (t,x,y,z) in separate subplots I'd like to zoom together. That is, when I use the "Zoom to Rectangle" tool on one plot, when I release the mouse all 3 plots zoom together.
Previously, I simply plotted all 3 axes on a single plot using different colors. But this is useful only with small amounts of data: I have over 2 million data points, so the last axis plotted obscures the other two. Hence the need for separate subplots.
I know I can capture matplotlib/pyplot mouse events (http://matplotlib.sourceforge.net/users/event_handling.html), and I know I can catch other events (http://matplotlib.sourceforge.net/api/backend_bases_api.html#matplotlib.backend_bases.ResizeEvent), but I don't know how to tell what zoom has been requested on any one subplot, and how to replicate it on the other two subplots.
I suspect I have the all the pieces, and need only that one last precious clue...
-BobC
The easiest way to do this is by using the sharex and/or sharey keywords when creating the axes:
from matplotlib import pyplot as plt
ax1 = plt.subplot(2,1,1)
ax1.plot(...)
ax2 = plt.subplot(2,1,2, sharex=ax1)
ax2.plot(...)
You can also do this with plt.subplots, if that's your style.
fig, ax = plt.subplots(3, 1, sharex=True, sharey=True)
Interactively this works on separate axes
for ax in fig.axes:
ax.set_xlim(0, 50)
fig.draw()