Tensorflow 2 Semantic Segmentation - loss function for two classes

I am trying to implement a U-net for semantic segmentation with two classes (foreground=1 and background=0) in the segmentation mask images, following this tutorial. They have used SparseCategoricalCrossentropy for OUTPUT_CLASSES = 3, as shown below: OUTPUT_CLASSES = 3 model = unet_model(output_channels=OUTPUT_CLASSES) model.compile(optimizer='adam', loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=['accuracy']) EPOCHS = 20 VAL_SUBSPLITS = 5 VALIDATION_STEPS = info.splits['test'].num_examples//BATCH_SIZE//VAL_SUBSPLITS model_history = model.fit(train_batches, epochs=EPOCHS, steps_per_epoch=STEPS_PER_EPOCH, validation_steps=VALIDATION_STEPS, validation_data=test_batches, callbacks=[DisplayCallback()]) If I use the same network with OUTPUT_CLASSES = 2 the training loss is NaN. What should I use …
Category: Data Science

what would be the correct representation of categorical variables like sex?

I have a doubt about what will be the right way to use or represent categorical variables with only two values like "sex". I have checked it up from different sources, but I was not able to find any solid reference. For example, if I have the variable sex I usually see this in this form: id sex 1 male 2 female 3 female 4 male So I found that one can use dummy variables like this: (https://www.analyticsvidhya.com/blog/2015/11/easy-methods-deal-categorical-variables-predictive-modeling/) and also …
Category: Data Science

Change target of view link in admin

We're developing across two sites. One site holds our content, the other actually displays it. So when we are viewing posts in the WP admin, the View link is pointing to the instance it's on, which doesn't help us when we want to view the post. For example, Data site: http://site1.com Viewing site: http://site2.com I need to change our view link on the Data site to something like: http://site2.com/12345 Is there a hook I can use to modify what is …
Category: Web

How do I add the featured image to the_content after the first paragraph?

My problem: I'm trying to create a filter that will add the featured image of a post to the_content, so that I can have the first paragraph of the_content displayed before this image. What I basicly want to achieve: <p>First Paragraph of the_content</p> <img>The Post's Featured Image</img> <p>The rest of the_content</p> I someone is able to help me. Thanks in advance!
Category: Web

Selector for page to set up scrolling plugin

I'm trying to set up infinite scrolling for pages on my site, using the Catch plugin. It asks for an item selector. The default is article.status-publish. I'm guessing that if I can figure out what the page selector is, that setting may do the job. I'm not familiar with CSS, have tried some reading, but all the guides about finding selectors seem to want much more CSS knowledge than I have. How can I make this "simple" plugin work? Thanks …
Category: Web

Identifying subsets of values significant to the total sum

Imagine a set of products in a store, with all the different attributes assigned to them - some of these hierarchical (e.g. categories), and some not (e.g. brand), but none of them continuous (if that is even important here). For each product, we know how much (in money-value) we've sold last year, and how much we sold this year. The sum of all of the differences in these sales is equal to the difference in total sales between the two …
Category: Data Science

Predict User Demographics from location based social networks

I am currently working on an lbsn (localization-based social network) system and i need to predict the user's age and gender. Every time a user enters a venue, the system creates a "check-in" with the user, the venue and the datetime. Every venue is categorized using Foursquare Venue Categories. The system generate a Weigthed Concept Hierarchy to represent the interest level between a user and a Venue Category. Is it possible to predict the user's age and gender using the …
Category: Data Science

Download file and redirect to page or vice versa

I have a Wordpress site with a custom post type called downloads. The post type has a file field added to it with Advanced Custom Fields (ACF). The downloads post type is used for download links spread across the site and I want them to sometimes be password protected using the native password protection of pages in Wordpress. When clicking a link to a downloads post type, you're directed to www.domain.com/?downloads=<NAME OF POST>&redirect=<CURRENT URL>. If the download is password protected, …
Category: Web

Same ACF Relationship field for multiple Post Options sub-pages?

How can I ensure that the data saved by an Advanced Custom Fields Relationship field, when on an Options page for a Post type, is separate? Detail below: I have an ACF field group, “Features”, containing a Relationship field. It is intended to allow me to pre-set some featured posts for a couple of custom post types – “Reports” and “Articles”. For those post types, in the same code that registers each post type, I have created an Options sub-page …
Category: Web

How to use prediction model after onehot encoding?

I have created a prediction model for this dataset >>df.head() Service Tasks Difficulty Hours 0 ABC 24 1 0.833333 1 CDE 77 1 1.750000 2 SDE 90 3 3.166667 3 QWE 47 1 1.083333 4 ASD 26 3 1.000000 >>df.shape (998,4) >>X = df.iloc[:,:-1] >>y = df.iloc[:,-1].values >>from sklearn.compose import ColumnTransformer >>ct = ColumnTransformer([("cat", OneHotEncoder(),[0])], remainder="passthrough") >>X = ct.fit_transform(X) >>x = X.toarray() >>x = x[:,1:] >>x.shape (998,339) >>from sklearn.ensemble import RandomForestRegressor >>rf_model = RandomForestRegressor(random_state = 1) >>rf_model.fit(x,y) How can I …
Category: Data Science

Good sources about advanced scraping?

I build many scraping based on node + puppeteer + PostgreSQL as data storage and queue. Everything works great, but I want to develop myself, my next goal to scraping data from + 100 000 000 pages (I have my proxy server with squid). When I can find sources to learn advanced scraping data, optimize performance, etc? What would you recommend to me?
Topic: javascript
Category: Data Science

How to get significativity for tabular data in machine learning?

Im using fastai to train a network on tabular data (https://docs.fast.ai/tutorial.tabular.html). I have a table with 5 columns, each of these is the specific attribute that describes a galaxy and helps to classify it into two types: elliptical and spiral. My question is: Is it possible to get the value of which of these attributes is most helpful/least helpful for the training? I mean some king of ranking.
Category: Data Science

sklearn MinMaxScaler: Inverse does not equal original

I am using MinMaxScaler on a large dataset (2201887, 3) to normalize features. Inversed values does not match originals. I tested with the target column, first (a), I applied the scaler on 10 values, then did the inverse transformation and I was able to get original values. Then (b), I inverted 10 normalized values after applying MinMaxScaler on the whole column and results were completely different : Result of (a) : Result of (b) : How can I have the …
Category: Data Science

How to bulk add vast amounts of posts

I'm looking for a way to automatically add a large number of example posts to a WordPress blog for testing purposes. I have the requirement to test a bulk process on 15,000 English blog posts (one or two paragraphs of text and nonsensical titles will do). As you can imagine, getting this volume of test content populated isn't something one would like to do by hand!
Category: Web

An error in Figure 13.13 of Bishop's PRML?

This figure comes from Chapter 13 Sequential Data in Bishop's Pattern Recognition and Machine Learning (PRML). I am not sure whether there is an error that it seems like the $$ p(\mathbf{x}_n|z_{n+1,k}), k=1,2,3 $$ in Figure 13.13 should be $$ p(\mathbf{x}_{n+1}|z_{n+1,k}), k=1,2,3 \,. $$ I am wondering can anyone who has read this book give me some advice?
Category: Data Science

Add starts rating in woocommerce product comment from backend

I collect reviews from different websites and I would like to be able to add them manually to my products in woocommerce, how can I add the star rating from the back office over the text? in the comment there is no metabox of the choice. I searched for this information and the only document found is this woocommerce report in the issue sections: https://github.com/woocommerce/woocommerce/issues/25656 can you help me understand how to add the rating change from the backoffice on …
Category: Web

Low classification accuracy

I want to do a multi class classification with 6 classes. Whole dataset has 12750 and 56 features samples, so every class has 2125 samples. Before prediction I reduces amount of outliers by winsorization (for 1 and 99 percentile) and I reduced skewness in features which has more than 1 and less than -1 skewness by Yeo-Johnson transformation and I got dataset: https://i.stack.imgur.com/miy8i.png Later, of course, I splitted dataset for 80% of training data and 20% of test data and …
Category: Data Science

How to train a spaCy language model from scratch?

I am still quite a beginner with spaCy (although I already do enjoy it). I would like to create a language model for a language still unsupported, that is from scratch. I do have comprehensive text corpora in this language. Where do I start and how to proceed? TIA.
Topic: spacy
Category: Data Science

WP_Query order posts by category

In a custom WP_Query I want to order posts by category. I mean that I want to show posts with term_id=1291 first and then show other posts. when I use two WP_Query , I cant use pagination. "edited" I tried this at first. I thought when I use post__in, wp_query ,keep posts order in post__in. $c_cat=$_GET["c_cat"] $query1 = new WP_Query(array( 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $c_cat, ) ) )); $query1_ids=array(); foreach ($query1->posts as …
Category: Web

The Global Styles missing

I am working on my first block-based theme, and trying to leverage theme.json as much as possible. I would like to allow client to change the the fonts, colors and other variations defined in the theme.json globally, for the whole site, and in the tutorials over the net I saw this can be done in the Global Styles menu. But, I don't see Global Styles menu in any of the block-based WP sites I have access to, including the Gutenberg …
Category: Web

order the meta query results by 2 custom fields

I have a custom post type 'brewery', I want to fetch results by 2 custom fields. The desired result is to get all posts with highest review rating (value is in decimal like 4.2 or 4.8) and if few posts have same review rating then I want to sort the results by review count (value is numeric and can be any number like 5, 400 or even 2500). Example: Post 1 -> Review rating = 4.8 & Review Count = …
Category: Web

Wordpress scheduled task is called but not executed

I created a plugin with a cron to update all posts of a certain type every 5 minutes. I installed WP Crontrol to check if the cron is registered correctly and everything seems to be okay. This is how I registered my cron: function custom_cron_interval( $schedules ) { $schedules['fiveminutes'] = array( 'interval' => 300, 'display' => __('Every five minutes') ); return $schedules; } add_filter( 'cron_schedules', 'custom_cron_interval' ); if ( ! wp_next_scheduled( 'recalculate_all_scores' ) ) { wp_schedule_event(time(), 'fiveminutes', 'recalculate_all_scores'); } It …
Category: Web

Support Vector Machines with soft margin: solving the dual form

I am currently struggling with finding an analytical solution for the $\alpha_k$. I have derived the following constrained optimization problem: $$ L = \sum_{i=1}^{N} \alpha_i - \frac{1}{2} \sum_{i=1}^{N}\sum_{j=1}^{N}\alpha_i \alpha_j y_i y_j (\textbf{x}_j^T \textbf{x}) $$ $$ s.t. \quad 0 \leq \alpha_i \leq C \quad \forall i, \quad \sum_{i=1}^{N} \alpha_i y_i = 0 $$ I had, at first, not taken the constraints into account which, after taking the derivative w.r.t. $\alpha_k$, gave me: $$ y_k \sum_{i=1}^{N} \alpha_i y_i (\textbf{x}_j^T \textbf{x}) = 1 …
Category: Data Science

Login page too many redirects

I have a custom plugin that handles the login and verification of customers. It creates default WordPress users with custom usermeta. But as an admin whenever I try to access the wp-admin dashboard on my live site I get an error page with too many redirects. This however works on my local dev site. Below is the function that fires after logging in and gives the error. function redirect_to_lvkg_login() { if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) { if ( is_user_logged_in() …
Category: Web

Automatically add images to a menu

I am calling a menu into a page, but I want to add images next to the title of the menu items. I have this code: <ol> <?php $navMenu = wp_get_nav_menu_items(2096); /*/Pass Nav Menu_id or Name*/ $previousMenuParent = $level = 0; foreach ($navMenu as $menu) { if($menu->menu_item_parent == 0) { $level = 0; echo '<li><a href="'. $menu->url .'"><img src="'. get_the_post_thumbnail($menu->ID) .'"/> '. $menu->title .'</a>'; } } ?> </li> It works, it is showing the list of the menu items, with …
Category: Web

Change default Video Player without Plugin

We all know there are various types of plugins to EMBED Video Players. My issue is, that I have a Theme, which links the Videos only with a link and not with some kinda Plugin. Is there any possible way to change the default Video Player Design hardcoded ? I didn't find a solution in the WWW.
Category: Web

How to normalize test data according to the training data if the normalization on the training data is performed row wise?

I read in several places about the normalization of features in the machine learning method. But I normalize my training data row-wise as shown in the following code. I showed only two samples of training data. My question is that while performing the normalization on test data, should I choose the minimum and maximum value of each test sample to normalize each test data, or should I uses the minimum and maximum values from the training data? As an explanation …
Category: Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.