I am using the following code to load resnet50 but since this is a video. I am not sure what is the expected input. Is it ([batch_size, channels, frames,img1,img2])?
Any help would be fantastic.
import pytorchvideo.models.resnet
def resnet():
return pytorchvideo.models.resnet.create_resnet(
input_channel=3, # RGB input from Kinetics
model_depth=50, # For the tutorial let's just use a 50 layer network
model_num_class=400, # Kinetics has 400 classes so we need out final head to align
norm=nn.BatchNorm3d,
activation=nn.ReLU,
)
Related
I have seen great examples of how bokeh allows you to hover over a data point and display pop up details for it. There are cases the details is so overwhelming voluminous, it really requires a side panel to display it all. Is bokeh a complete enough widget toolkit where I can create a side panel to the main display and show details of a data point following the cursor?
Can someone point out some sample code, or at least the relevant api's.
If you prefer a higher-level API for building and linking Bokeh-based plots, you can use HoloViews; see linking examples at http://holoviews.org/reference/index.html#streams and instructions at http://holoviews.org/user_guide/Custom_Interactivity.html . For example:
import param, numpy as np, holoviews as hv
from holoviews import opts, streams
hv.extension('bokeh')
xvals = np.linspace(0,4,202)
ys,xs = np.meshgrid(xvals, -xvals[::-1])
img = hv.Image(np.sin(((ys)**3)*xs))
pointer = streams.PointerXY(x=0,y=0, source=img)
dmap = hv.DynamicMap(lambda x, y: hv.Points([(x, y)]), streams=[pointer])
dmap = dmap.redim.range(x=(-0.5,0.5), y=(-0.5,0.5))
img + dmap.opts(size=10)
You can find many examples on https://docs.bokeh.org . What you want is possible by adding a callback and updating the relevant part. In this example the div is what you name a side panel in your question.
#for bokeh 1.0.4
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource,Div,Row
from bokeh.io import curdoc
from bokeh.events import Tap
#the data
d={'x':[1,2],'y':[3,4],'info':['some information on a first datapoint','some information on a second datapoint']}
source=ColumnDataSource(d)
tooltips = [("x", "$x"),("y", "$y"),("info","#info")]
fig=figure(tools="tap,reset",tooltips=tooltips)
c=fig.circle('x','y',source=source,size=15)
def callback(event):
indexActive=source.selected.indices[0]
layout.children[1]=Div(text=d['info'][indexActive])#adjust the info on the right
fig.on_event(Tap, callback)
div=Div(text=d['info'][0])
layout=Row(fig,div)
curdoc().add_root(layout)
To run this code, save it as code.py, open a cmd and type "bokeh serve code.py --show".
I am trying to import a matplotlib to html with xkcd theme. My code is as follows (no data,just a fig)
fig = plt.figure(facecolor = '#eee8d5')
#plt.matplotlib.rcdefaults()
with plt.xkcd():
ax = fig.add_subplot(111)
ax.set_axis_bgcolor('#eee8d5') #set_color('#fdf6e3')
ax.title.set_color('#d33682') # Magenta
ax.tick_params(axis='x', colors='#657b83')
ax.tick_params(axis='y', colors='#657b83')
ax.spines['bottom'].set_color('#657b83')
ax.spines['left'].set_color('#657b83')
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.set_title('Title', fontsize = 18);
html = mpld3.fig_to_html(fig)
Html_file= open("CumPrctWordFrq.html","w")
Html_file.write(html)
Html_file.close()
So far so good -- everything renders correctly in the python notebook. However when I paste the html on a website (squarespace), the fig loses all the xkcd properties. Eventually I would like to make this interactive. The idea is eventually to produce a xkcd -> solarized -> interactive plot.
mpld3 does not yet support the plt.xkcd() mode. If this is something you want, you should creat an issue in the mpld3 issue tracker, and see if someone is inspired to work on it.
I have a simple extension for the Sphinx documentation utility (my version in use isSphinx-1.1.3-py2.6). Very much like this excellent example by Doug Hellmann. How can I add a rel='bar' attribute to the final HTML for the <a ...> tag?
The reference nodes are created in this fashion:
node = nodes.reference(rawtext, utils.unescape(text),
internal=False,
refuri=ref,
classes=['foocss'],
rel='bar',
**options)
However, the rel='bar' attribute gets stripped out from the final HTML markup. Hunting through the source got me to sphinx/writers/html.py and the HTMLTranslator class. Here is part of the visit_reference method:
# overwritten
def visit_reference(self, node):
atts = {'class': 'reference'}
<snip>
if 'reftitle' in node:
atts['title'] = node['reftitle']
self.body.append(self.starttag(node, 'a', '', **atts))
Additional attributes are not handled. Maybe they could be replaced in others parts. I couldn't find anything useful in that respect.
So, I could:
create a custom node which re-implements all the functionality of the reference node. A fair bit of work for a small addition.
Overwrite the visit_reference method in sphinx/writers/html.py. Quicker, but bad in terms of future Sphinx updates.
Add the rel attribute with jQuery to the link tag after the fact. Well, not pretty either.
I managed to do this with download_reference. Using app.add_node I override the visit_... method:
import posixpath
from sphinx.writers.html import HTMLTranslator
from sphinx.addnodes import download_reference
def visit_download_reference(self, node):
if node.hasattr('filename'):
self.body.append(
'<a class="reference download internal" href="%s" %s>' %
(posixpath.join(self.builder.dlpath, node['filename']), 'rel="%s"' % node['rel'] if node.get('rel', None) else ''))
self.context.append('</a>')
else:
self.context.append('')
def setup(app):
app.add_node(download_reference, html=(visit_download_reference, HTMLTranslator.depart_download_reference))
full extension is here
I need to create a .DAE file from one DisplayObject3D and do not know how to do it. Only I find information about how importing a DAE. Never of how exporting it.
Thanks.
I cannot change simply "mesh" for "container".
I do not understand this line very well:
mesh = scene.addChild(new PaperPlane(new FlatShadeMaterial(light,0xFFFF00,0xFF6600),3));
If I do this:
mesh = container.addChild(new PaperPlane(new FlatShadeMaterial(light,0xFFFF00,0xFF6600),3));
Then it creates a dae with the paperplane but only the paperplane and not other objects that exist in "container".
How can I create the dae with the objects of my DisplayObject3D "container"?
Thanks
You can write a .DAE file using ExportCollada's export() static method:
trace(ExportCollada.export(yourDisplayObject3D));
I've put together a very basic example here:
Run the test and double click the stage to save the plane as a .dae file to disk.
Update
Nesting objects also work as you can see here:
You mentioned this line:
mesh = scene.addChild(new PaperPlane(new FlatShadeMaterial(light,0xFFFF00,0xFF6600),3));
That is just a lazy way to doing multiple things in one line:
create a new PaperPlane object
add it to the scene
assign the PaperPlane object to the mesh variable
It probably makes more sense like this:
var mesh:DisplayObject3D = new PaperPlane(new FlatShadeMaterial(light,0xFFFF00,0xFF6600),3);
scene.addChild(mesh);
Your modified snippet:
mesh = container.addChild(new PaperPlane(new FlatShadeMaterial(light,0xFFFF00,0xFF6600),3));
says that mesh is equal to the DisplayObject3D returned by adding the paper plane to container, which is the paper plane, so if you're exporting mesh, you only export the plane.
If you export container, you should get the dae with all the child elements that container has.
Might be easier to change this line:
data.writeUTFBytes(ExportCollada.export(mesh));
to this:
data.writeUTFBytes(ExportCollada.export(container));//assuming container is visible here
I want to use a QGraphicWebView inside a delegate to render a QTableView cell, but I just don't know what to do with the QStyleOptionGraphicsItem parameter the paint() method requires. How to build it up / where should I retrieve it?
I'm using this code as reference, so the paint() method should be something like this:
def paint(self, painter, option, index):
web = QGraphicsWebView()
web.setHtml(some_html_text)
web.page().viewportSize().setWidth(option.rect.width())
painter.save()
painter.translate(option.rect.topLeft());
painter.setClipRect(option.rect.translated(-option.rect.topLeft()))
web.paint(painter, ??????) # what here?
painter.restore()
Any advice?
I'll assume that you don't really need QGraphicsWebView and that QWebView is sufficient.
It's important to keep in mind that you're not expected to call QWidget::paintEvent() yourself. Given that constraint, you'll want to use a helper class that can render on a paint device or render using a given painter. QWebFrame has one such method in the form of its render function. Based off of your linked-to example, the following should work:
class HTMLDelegate(QStyledItemDelegate):
def paint(self, painter, option, index):
model = index.model()
record = model.listdata[index.row()]
# don't instantiate every time, so move this out
# to the class level
web = QWebView()
web.setHtml(record)
web.page().viewportSize().setWidth(option.rect.width())
painter.save()
painter.translate(option.rect.topLeft());
painter.setClipRect(option.rect.translated(-option.rect.topLeft()))
web.page().mainFrame().render(painter)
painter.restore()