Categories
Behaviour chicken_research The Chicken Experience

Notes for looking after my chicken

Below are the notes I left, for my housemates, to look after my chicken, Alpha, while I’m away in Europe, for MFRU.

Alpha feeding

What she’s supposed to eat, as a chicken:

Maize, sorghum, sunflower seeds, leftover vegetable scraps, and enough calcium for egg shell development. So, crumple some egg shells in the garden occasionally. 

But she’ll only eat maize and sorghum if she’s really hungry. She likes sunflower seeds.

Her faves in decreasing order are:

Superworms 

Live Larvae

Dead Larvae

Bread 

Cooked rice

(De-shelled) Sunflower seeds

There’s various grains and pulses like millet, rice, lentils, which she’ll eat, if it’s cooked. 

When she does the loud alarm noises, or jumps on the table outside Chris’s room, it’s usually the black and white cat. But sometimes it means she’s looking for a place to lay an egg. 95% of the time, she will go back and lay the egg in her box/bed. I think when she crouches down, when you approach, it’s a similar vibe. 

Her house has a few features, which need adjustment occasionally. There’s two waterproof umbrella cloths on top, for the rain, usually held in place by a branch, and there’s some polystyrene directly above the box. The box is raised, because she prefers to be higher off the ground, when sleeping. It’s not necessary but after about 6:30pm, when she’s in bed, you can put the ‘satanic apron’ over her box. But first have a quick check for mosquitoes in the box. If there’s lots of mosquitoes, make sure there’s not some sitting water with mosquito larvae in the backyard somewhere. The apron offers a bit more protection from the cold, and light. The chicken house could use some work, but usually it’s fine unless it’s been very windy or rainy.

I change her bedding once a month or so, or if it gets wet in there, after a rain, or if she poops her bed, I’ll take the poop out. Straw or that Alfalfa/Lucerne in the plastic bag works for bedding. 

Um… what else… when you steal the eggs, try not to let her see the egg, or she’ll make disapproving sounds.

I change the water every day or two. There doesn’t need to be as many water containers as there are, but just make sure there’s some water around, that the little rat doves haven’t shat in. 

Alpha won’t eat the maize, so you can throw a handful in a spot, and the little doves will eat it.

The worms and larvae are pretty good at hiding but there should be a few hundred of each left. Just throw some wet scraps in, occasionally. They’re eating melted instant coffee, and cardboard and grass at the moment. 

Alpha will eat as many worms as you give her, so try limit to 10. Internet says 2/day. But that’s for normal, not-spoiled chickens. 

She’s picky, until there’s no choices, and then if she’s hungry, she’ll eat whatever’s going. The internet usually knows what she can eat, if you’re going to feed her something new. Usually if it’s grainy or pulsey, or crumby, or anything meaty, or insecty, she’ll give it a try.

Leave some sunflower seeds on top of the bucket where the little rat doves can’t see.

She doesn’t understand pointing at things, or English. But she will usually understand food in hand, or food put in front of her. 

Ok that’s the gist. Thanks.

Categories
highly speculative highly_speculative The Chicken Experience

Consciousness and Potential

A controversial thought… but, when considering the 7 billion male chicks that are destroyed within a day of hatching (per year), what sort of difference exists, between the mind of a baby chick, and a baby human? The conscious experience, (perhaps not yet encumbered by self-modeled reflection, and the psychological maturity of complex thought), still exists in some way. It is like something, to be a living being. Mammals and Birds share a common ancestor, a few hundred million years back, and we both are born, innately knowing, and preferring some things over others.

If there were a debate, with one side seeing infanticide as worse than what we do to chickens, it would probably just come down to ‘the argument from potential’ – and yet… chickens are smarter than human toddlers. I guess that argument needs to change to ‘long term potential’?

Hmm. Interesting thought, anyway.

The topic of how babies and chicks are similar interests others too. (“Born Knowing”, Giorgio Vallortigara)

Categories
chicken research chicken_research control sexing The Chicken Experience

DIY Incubator

Just a quick write-up on the incubator I made, for the fertilized eggs we picked up recently. They were R5 each (€0.28). The goal is to maintain a temperature of 37.5C.

The incubator consists of:

  • Arduino Nano
  • DS18B20 temperature sensor
  • 4.7K resistor
  • Solid state relay module
  • 12V power supply (for the Arduino, and relay)
  • A relatively inefficient 20W light, on a heatsink.
  • Some aluminium foil, in a mostly closed plastic container

    The eggs were placed a bit above the heatsink, in an egg carton, (hot air rises.) The idea being that we only want conductive heat, not radiative heat, since radiative heat is directional, and will heat one side of the egg more than the other side.

    The Arduino code was adapted from the example code from the OneWire library. The controller measures the temperature at the eggs, and turns on the light when the temperature is below 37.5C, and turns it off when it’s above. Using a separate temperature sensor, we confirmed that the temperature remains within a degree of the desired temperature.

There are better ways to do this, I’m sure, but this is what I came up with, on a day’s notice, with the parts available.

The gotchas encountered were, that the Chinese Arduino Nano I used required selecting to upload the sketch, for the ‘old’ bootloader, and the wiring colours of the DS18B20 were incorrectly labelled, (as it was for this forum user).

#include <OneWire.h>

// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// https://github.com/milesburton/Arduino-Temperature-Control-Library



#define SENSOR 2
#define LIGHT 4

OneWire  ds(SENSOR);  // on pin 2 (a 4.7K resistor is necessary)

float desired_temp = 37.5;
float light_status = LOW;



void control(float temperature){
  if (temperature >= desired_temp)
  {
    light_status = LOW;
    Serial.println("HEATER OFF");
    
  }
  else 
  {
    light_status = HIGH;
    Serial.println("HEATER ON");
  }
  digitalWrite(LIGHT, light_status);
}

void setup(void) {
  Serial.begin(9600);
  pinMode(LIGHT, OUTPUT); 
}

void loop(void) {
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
  
  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }
  
  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();
 
  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  } 

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
  
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");

  control(celsius);
}

As the eggs reach maturity, we’ll get a ‘hatcher’ environment ready.

Categories
bio chicken research CNNs evolution sexing Vision

Speckled eggs

Finally tried shining light through an egg, and discovered calcium deposits making things opaque. Hmm.

This led to finding out about all these abnormal eggs.

Categories
Behaviour bio chicken research chicken_research deep dev ears institutes neuro The Chicken Experience

Stress Vocalisations

We’ve spoken with Dr. Maksimiljan Brus, at the University of Maribor, and he’s sent us some WAV file recordings of a large group of chickens.

There seems to be a decent amount of work done, particularly at Georgia Tech, regarding categorizing chicken sounds, to detect stress, or bronchitis, etc. They’ve also done some experiments to see how chickens react to humans and robots. (It takes them about 3 weeks to get used to either).

In researching the topic, there was a useful South African document related to smallholding size chicken businesses. It covers everything. Very good resource, actually, and puts into perspective the relative poverty in the communities where people sell chickens for a living. The profit margin per chicken in 2013 was about R12 per live chicken (less than 1 euro).

From PRODUCTION GUIDELINES
for Small-Scale Broiler Enterprises
K Ralivhesa, W van Averbeke
& FK Siebrits

So anyway, I’m having a look at the sound files, to see what data and features I can extract. There’s no labels, so there won’t be any reinforcement learning here. Anomaly detection doesn’t need labels, and can use moving window statistics, to notice when something is out of the ordinary. So that’s what I’m looking into.

I am personally interested in Numenta’s algorithms, such as HTM, which use a model of cortical columns, and sparse encodings, to predict, and detect anomalies. I looked into getting Nupic.critic working, but Nupic is so old now, written in Python 2, that it’s practically impossible to get working. There is a community fork, htm.core, updated to Python 3, but it’s missing parts of the nupic codebase that nupic.critic is relying on. I’m able to convert the sound files to the nupic format, but am stuck for now, when running the analysis.

So let’s start at a more basic level and work our way up.

I downloaded Praat, an interesting sound analysis program used for some audio research. Not sure if it’s useful here. But it’s able to show various sound features. I’ll close it again, for now.

So, first thing to do, is going to be Mel spectrograms, and possibly Mel Frequency Cepstral Coefficients (MFCCs). The Mel scale kinda allows a difference between 250Hz and 500Hz to be scaled to the same size as a difference between 13250Hz and 13500Hz. It’s log-scaled.

Mel spectrograms let you use visual tools on audio. Also, worth knowing what a feature is, in machine learning. It’s a measurable property.

Ok where to start? Maybe librosa and PyOD?

pip install librosa

Ok and this outlier detection medium writeup, PyOD, says

Neural Networks

Neural networks can also be trained to identify anomalies.

Autoencoder (and variational autoencoder) network architectures can be trained to identify anomalies without labeled instances. Autoencoders learn to compress and reconstruct the information in data. Reconstruction errors are then used as anomaly scores.

More recently, several GAN architectures have been proposed for anomaly detection (e.g. MO_GAAL).

There’s also the results of a group working on this sort of problem, here.

A relevant arxiv too:

ANOMALOUS SOUND DETECTION BASED ON
INTERPOLATION DEEP NEURAL NETWORK

And

UNSUPERVISED ANOMALOUS SOUND DETECTION VIA AUTOENCODER APPROACH

What is this DCASE?

Hmm so there is a challenge for it currently. It’s big in Japan. Here’s the winning solution:

Amazon programmers win an Amazon competition on anomaly detection.

Here was an illustrative example of an anomaly, of some machine sound.

And of course, there are more traditional? algorithms, (data-science algorithms). Here’s a medium article overview, for a submission to a heart murmur challenge. It mentions kapre, “Keras Audio Preprocessors – compute STFT, ISTFT, Melspectrogram, and others on GPU real-time.”

And I found ‘torchaudio‘,

Here’s a useful flowchart from a paper about edge sound analysis on a Teensy. Smart Audio Sensors (SASs). The code “computes the FFT and Mel coefficients of a recorded audio frame.”

Smart Audio Sensors in the Internet of Things
Edge for Anomaly Detection

I haven’t mentioned it, but of course FFT, Fast Fourier Transform, which converts audio to frequency bands, is going to be a useful tool, too. “The FFT’s importance derives from the fact that it has made working in the frequency domain equally computationally feasible as working in the temporal or spatial domain. ” – (wikipedia)

On the synthesis and possibly artistic end, there’s also MelGAN and the like.

Google’s got pipelines in kubernetes ? MLOps stuff.

Artistically speaking, it sounds like we want spectrograms. Someone implements one from scratch here, and there is a link to a good youtube video on relevant sound analysis ideas. Wide-band, vs. narrow-band, for example. Overlapping windows? They’re explaining STFT, which is used to make spectrograms.

There’s also something called Chirp Z transform.

Anyway. Good stuff. As always, I find the hardest part is finding your way back to your various dev environments. Ok I logged into the Jupyter running in the docker on the Jetson. ifconfig to get the ip, and http://192.168.101.115:8888/lab, voila).

Ok let’s see torchaudio’s colab… and pip install, ok… Here’s a summary of the colab.

Some ghostly Mel spectrogram stuff. Also, interesting ‘To recover a waveform from spectrogram, you can use GriffinLim.’

Ok let’s get our own dataset prepared. We need an anomaly detector. Let’s see…

———————— <LIBROSA INSTALLATION…> —————

Ok the librosa mel spectrogram is working, at least, so far. So these are the images for the 4 files Dr. Brus sent.

While looking for something like STFT to make a spectogram video, i came across this resource: Machine Hearing. Also this tome of ML resources.

Classification is maybe the best way to do this ML stuff. Then you can add labels to classes, and train a neural network to associate labels, and to categorise. So it would be ideal, if the data were pre-labelled, i.e. classified by chicken stress vocalisation experts. Like here is a soundset with metadata, that lets you classify sounds with labels, (with training).

So we really do need to use an anomaly detection algorithm, because I listened to the chickens for a little bit, and I’m not getting the nuances.

Here’s a relevant paper, which learns classes, for retroactive labelling. They’re recording a machine making sounds, and then humans label it. They say 1NN (k-nearest-neighbours) is hard to beat, but it’s memory intensive. “Nearest centroid (NC) combined with DBA has been shown to be competitive with kNN at a much smaller computational cost”.

Here’s pyAudioAnalysis

Perform unsupervised segmentation (e.g. speaker diarization) and extract audio thumbnails

  • Train and use audio regression models (example application: emotion recognition)
  • Apply dimensionality reduction to visualize audio data and content similarities

Here’s a cool visualiser, in tensorboard,

Ideally, I would like to use NuPIC.

https://numenta.com/resources/biological-and-machine-intelligence/

Ok, let’s hope this old link works, for a nupic docker.

sudo docker run -i -t numenta/nupic /bin/bash

Ok amazing. Ok right, trying to install matplotlib inside the docker crashes. urllib3. I’ve been here before. Right, I asked on the github issues. 14 days ago, I asked. I got htm.core working. But it doesn’t have nupic.data classes.

After bashing my head against the apparent impossibility to pip install urllib3 and matplotlib in a python 2.7 docker, I’ve decided I will have to port the older nupic.critic or nupic.audio code to htm.core.

I cleared up some harddrive space, and ran this docker:

docker run -d -p 8888:8888 --name jupyter 3rdman/htm.core-jupyter:latest

then get the token for the URL:
docker logs -f jupyter

There’s a lot to go through, and I’m a noob at HTM. So I will start a new article now, on HTM specifically, for this.

Categories
evolution highly speculative highly_speculative meta The Chicken Experience

Ameglian Major Cow, Chairdogs, etc.

I thought it’s probably worth noting some sci-fi ideas that I remember…

The Ameglian Major Cow (or, Dish of the Day), was the cow in Hitchhiker’s guide book 2, (Restaurant at the end of the Universe), that has been bred to want to be eaten, and when Zaphod Beeblebrox, etc., order steak, the cow goes off to shoot itself, and tells the protagonist, Arthur not to worry: “I’ll be very humane.”

The other thing was chairdogs, that show up in one of the later Dune books. The Tleilaxu are known for taking genetic engineering a bit too far, and one of their exports is a dog that’s been bred until it has become a chair, which massages you. Real ‘creature comforts’. It’s generally used for world building and character development, maybe insinuating that the characters with guilty-pleasure chairdogs, are getting soft.

Interesting, because the artificial selection or genetic engineering leading to these creations is questionable, but the final product is something that inverts or sidesteps morality.

The Ameglian Major Cow is a common thought experiment, as it postulates a question to vegetarians, whether they would eat meat, if it were intelligent, and wanted to be eaten. It’s very hypothetical though.

Chairdogs are closer: if chickens of tomorrow, or other domesticated animals, are ultimately evolved or engineered into simplified protein vats, their ‘souls’ (i.e. CNS) removed, perhaps we’re left with something less problematic, despite the apparent abominating of nature.

Side note: Alex O’Connor, Cosmic Skeptic, has a lot to say, on the philosophy of ethical veganism. Here he answers a question: “Do Animals have a “Right to Life?” – (tl;dw: no. but you should eat less meat)

Categories
chicken research The Chicken Experience

Potential Collaboration With Maribor University Agri-sciences dept.?

oooo, they have an experimental farm, with poultry too:

http://fkbv.um.si/index.php/en/research-development-and-innovations?start=2

Starting Questions for them:

  • What research are they doing with chickens?
  • What kinds of robots are the agri department working on? We see they’ve done really well at the International Field Robot Event – cool!
  • Do they have / know about layer chickens whose “female day-old chicks have brown down feathers and the males have yellow down feathers” (https://doi-org.proxy.lnu.se/10.3382/ps/pew282), or similar?
  • possibility to make a dataset from eggs especially if they are sexing them in some other way?
  • Neural network training – onsite datacentre? or using AWS or GCP?
  • “Dual-purpose” chicks?
  • How are they using robotics and automation in agriculture and what kind of crazy sci-fi stories can we get out of them.
  • Maybe cool equipment? (e.g. hyperspectral camera…)
  • How could our work be interesting for them? – public awareness on some issue/s?

Categories
AI/ML chicken research chicken_research The Chicken Experience

Broiler stunned

“When applied to a reinforcing dataset containing 27,828 images of chickens in a stunned state, the identification accuracy of the model was 98.06%. This was significantly higher than both the established back propagation neural network model (90.11%) and another Faster-RCNN model (96.86%). The proposed algorithm can complete the inspection of the stunned state of more than 40,000 broilers per hour. The approach can be used for online inspection applications to increase efficiency, reduce labor and cost, and yield significant benefits for poultry processing plants.” https://www.sciencedirect.com/science/article/pii/S0032579119579093

Their abstract frames benefit in terms of slaughtering efficiency. Interesting ‘local optima’ ethics-wise. But yes, since we kill 178 million broiler chickens a day, we should at least have an AI checking that the stunning worked. Perhaps implement some “Ethics policy” to re-stun the chicken, if not properly stunned.

(Stunning means the conveyor belt dipping chickens’ heads into electrified water, to stun them, so their heads dangle and can be ripped off mechanically)

Categories
AI/ML Behaviour chicken research CNNs Vision

Egg ID

This is a notably relevant paper from 2019, that appears to be keeping track of eggs

“Our custom SSD object detection and classification model classified when chickens and eggs were detected by the video camera. Our models can label video frames with classifications for 8 breeds of chickens and 4 colors of eggs, with 98% accuracy on chickens or eggs alone and 82.5% accuracy while detecting both types of objects.”


“Tuned accuracy is needed for proper thresholding of object detection”

https://scholar.smu.edu/cgi/viewcontent.cgi?article=1073&context=datasciencereview (https://scholar.smu.edu/datasciencereview/vol2/iss1/20/)

Also interesting,

Factors Affecting Egg Production in Backyard Chicken
Flocks

https://edis.ifas.ufl.edu/pdffiles/ps/ps02900.PDF

Categories
chicken research highly speculative The Chicken Experience

Odd chicken neural nets

These people are training neural nets on chicken shit https://www.hindawi.com/journals/js/2019/3823515/

And these guys are training neural nets on slaughtered chickens https://arxiv.org/abs/1906.11893

Meanwhile Chicken SkyNet is basically a thing: https://www.cambridge.org/core/journals/animal/article/review-automated-techniques-for-monitoring-the-behaviour-and-welfare-of-broilers-and-laying-hens-towards-the-goal-of-precision-livestock-farming/7D334A718C877E8E8F8DDB660EC98A4F/core-reader